import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < cases; i++) {
String dic1 = br.readLine();
String dic2 = br.readLine();
dic1 = dic1.substring(1, dic1.length() - 1);
dic2 = dic2.substring(1, dic2.length() - 1);
HashMap<String, String> hm = new HashMap<String, String>();
ArrayList<String> add = new ArrayList<String>();
ArrayList<String> sub = new ArrayList<String>();
ArrayList<String> change = new ArrayList<String>();
if (!dic1.equals("") && !dic2.equals("")) {
String[] str = dic1.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
hm.put(ans[0], ans[1]);
sub.add(ans[0]);
}
str = dic2.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
if (hm.containsKey(ans[0])) {
sub.remove(ans[0]);
String val = hm.get(ans[0]);
if (!val.equals(ans[1])) {
change.add(ans[0]);
}
} else {
add.add(ans[0]);
}
}
}else if(dic1.equals("")&&!dic2.equals("")){
String[]str = dic2.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
add.add(ans[0]);
}
}else if(!dic1.equals("")&&dic2.equals("")){
String[]str = dic1.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
sub.add(ans[0]);
}
}
if(!add.isEmpty()){
Collections.sort(add);
}
if(!sub.isEmpty()){
Collections.sort(sub);
}
if(!change.isEmpty()){
Collections.sort(change);
}
boolean first = true, enterOnce = false, entered = false;
while (!add.isEmpty()) {
if (first) {
sb.append("+");
first = false;
} else {
sb.append(",");
}
sb.append(add.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
entered = false;
first = true;
while (!sub.isEmpty()) {
if (first) {
sb.append("-");
first = false;
} else {
sb.append(",");
}
sb.append(sub.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
first = true;
entered = false;
while (!change.isEmpty()) {
if (first) {
sb.append("*");
first = false;
} else {
sb.append(",");
}
sb.append(change.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
if (!enterOnce) {
sb.append("No changes\n");
}
sb.append("\n");
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < cases; i++) {
String dic1 = br.readLine();
String dic2 = br.readLine();
dic1 = dic1.substring(1, dic1.length() - 1);
dic2 = dic2.substring(1, dic2.length() - 1);
HashMap<String, String> hm = new HashMap<String, String>();
ArrayList<String> add = new ArrayList<String>();
ArrayList<String> sub = new ArrayList<String>();
ArrayList<String> change = new ArrayList<String>();
if (!dic1.equals("") && !dic2.equals("")) {
String[] str = dic1.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
hm.put(ans[0], ans[1]);
sub.add(ans[0]);
}
str = dic2.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
if (hm.containsKey(ans[0])) {
sub.remove(ans[0]);
String val = hm.get(ans[0]);
if (!val.equals(ans[1])) {
change.add(ans[0]);
}
} else {
add.add(ans[0]);
}
}
}else if(dic1.equals("")&&!dic2.equals("")){
String[]str = dic2.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
add.add(ans[0]);
}
}else if(!dic1.equals("")&&dic2.equals("")){
String[]str = dic1.split(",");
for (int j = 0; j < str.length; j++) {
String[] ans = str[j].split(":");
sub.add(ans[0]);
}
}
if(!add.isEmpty()){
Collections.sort(add);
}
if(!sub.isEmpty()){
Collections.sort(sub);
}
if(!change.isEmpty()){
Collections.sort(change);
}
boolean first = true, enterOnce = false, entered = false;
while (!add.isEmpty()) {
if (first) {
sb.append("+");
first = false;
} else {
sb.append(",");
}
sb.append(add.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
entered = false;
first = true;
while (!sub.isEmpty()) {
if (first) {
sb.append("-");
first = false;
} else {
sb.append(",");
}
sb.append(sub.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
first = true;
entered = false;
while (!change.isEmpty()) {
if (first) {
sb.append("*");
first = false;
} else {
sb.append(",");
}
sb.append(change.remove(0));
enterOnce = true;
entered = true;
}
if (entered) {
sb.append("\n");
}
if (!enterOnce) {
sb.append("No changes\n");
}
sb.append("\n");
}
System.out.print(sb);
}
}
No comments:
Post a Comment