Compare two dictionaries output all additions to delete modifications by dictionary if there is no update output no changes
Map Application Comparison Two dictionaries note that the processing of the starting string and the dictionary can be empty
Import Java.math.BigInteger;
Import java.util.Collections;
Import Java.util.HashMap;
Import Java.util.Iterator;
Import Java.util.Map;
Import Java.util.Scanner;
Import Java.util.Vector;
public class Main {public static void main (string[] args) {Scanner scan = new Scanner (system.in);
int n = scan.nextint ();
while (n--! =0) {map<string,biginteger> one = new hashmap<> (); vector<string> ins = new vector<> ()//Added key vector<string> des = new vector<> ();//Reduced key Vector <String> upd = new vector<> ()//modified key vector<string> bal = new vector<> ();/immutable key String str1
= Scan.next ();
String str2 = Scan.next ();
String SS1 = str1.substring (1, Str1.length ()-1);
String SS2 = str2.substring (1, Str2.length ()-1);
string[] S1 = Ss1.split (",");
string[] s2 = Ss2.split (","); for (int i=0;i<s1.length;i++) {if (!) ( S1[i].equals ("") | |
S1[i].equals ("")) {int index = s1[i].indexof (': '); String name = S1[i]. substring (0, index);
BigInteger num = new BigInteger (s1[i].substring (index+1));
One.put (name, num); } for (int i=0;i<s2.length;i++) {if (!) ( S2[i].equals ("") | |
S2.equals ("")) {int index = s2[i].indexof (': ');
String name = s2[i].substring (0, index);
BigInteger num = new BigInteger (s2[i].substring (index+1));
if (!one.containskey (name)) {Ins.add (name);
Continue
}else{BigInteger B = one.get (name);
if (B.compareto (num)!=0) {one.put (name, New BigInteger ("-1"));
}else{one.put (name, New BigInteger ("-2"));
iterator<map.entry<string, biginteger>> entries = One.entryset (). iterator ();
BigInteger A1 = new BigInteger ("-1");
BigInteger A2 = new BigInteger ("-2");
while (Entries.hasnext ()) {map.entry<string, biginteger> Entry = Entries.next ();
if (Entry.getvalue (). CompareTo (A2) ==0) {Bal.add (Entry.getkey ()); }else if (Entry.getvalue (). CompAreto (A1) ==0) {Upd.add (Entry.getkey ());
}else{Des.add (Entry.getkey ());
} collections.sort (INS);
Collections.sort (DES);
Collections.sort (UPD);
Collections.sort (BAL);
if (Upd.isempty () &&ins.isempty () &&des.isempty ()) {System.out.println ("No changes");
}else{if (!ins.isempty ()) {System.out.print ("+");
for (int i=0;i<ins.size (); i++) {if (I!=ins.size ()-1) {System.out.print (Ins.get (i) + ",");
}else{System.out.print (Ins.get (i));
}//if (N!=0) System.out.println ();
} if (!des.isempty ()) {System.out.print ("-");
for (int i=0;i<des.size (); i++) {if (I!=des.size ()-1) {System.out.print (Des.get (i) + ",");
}else{System.out.print (Des.get (i));
}//if (N!=0) System.out.println ();
} if (!upd.isempty ()) {System.out.print ("*"); for (int i=0;i<upd.size (); i++) {if (I!=upd.size ()-1) {SYSTEM.OUT.PRint (Upd.get (i) + ",");
}else{System.out.print (Upd.get (i));
}//if (N!=0) System.out.println ();
}//if (N!=0) System.out.println ();
} public static int f (String str1,string str2) {if (Str1.equals (str2)) {return 0;
}else{int index1 = Str1.indexof (":");
int index2 = Str2.indexof (":");
BigInteger B1 = new BigInteger (str1.substring (index1+1));
BigInteger b2 = new BigInteger (str2.substring (index2+1));
Return B2.compareto (B1); }
}
}