c-updating a DictionaryTime
limit:1000MS
Memory Limit:131072KB
64bit IO Format:%lld &%ll U Submit Status Practice CSU 1113
Description
In this problem, a dictionary is collection of key-value pairs, where keys be lower-case letters, and values are non -negative integers. Given an old dictionary and a new dictionary, find out what were changed.Each dictionary is formatting as follows:{key:value,key:value,..., key:value}Each key was a string of lower-case letters, and each value is a non-negative integer without leading zeros or prefix ' + '. (i.e. -4, and +77 are illegal). Each key would appear at the most once, but the keys can appear in any order.
Input
The first line contains the number of test Cases T (t<=1000). Each test case contains the lines. The first line contains the old dictionary, and the second line contains the new dictionary. Each line would contain at the most characters and would not be contain any whitespace characters. Both dictionaries could be empty.
WARNING:There is no restrictions on the lengths of all keys and value in the dictionary. That means keys could is really long and values could be really large.
Output
for each test case, print the changes, formatted as follows:· First, if there is any new keys, print ' + ' and then the new keys in increasing order (lexicographically), separated by co MMAs.· Second, if there is any removed keys, print '-"and then the removed keys in increasing order (lexicographically), Separa Ted by commas.· Last, if there is any keys with changed value, print ' * ' and then these keys in increasing order (lexicographically), Sep Arated by commas.If The dictionaries is identical, print ' No changes ' (without quotes) instead.Print a blank line after each test case.
Sample Input
3{a:3,b:4,c:10,f:6}{a:3,c:5,d:10,ee:4}{x:1,xyz:123456789123456789123456789}{xyz:123456789123456789123456789,x : 1}{first:1,second:2,third:3}{third:3,second:2}
Sample Output
Test instructions: Give you two dictionaries, look for the difference between two dictionaries. A simulation problem, note that both dictionaries are likely to be empty dictionaries, where the pit, and again to see the pit point.
If the first dictionary does not have, and the second dictionary contains, output + then output the second dictionary inside there and the first dictionary does not.
If the second dictionary does not have, and the first dictionary has, input-and then output the first dictionary inside there and the second dictionary does not.
If the first dictionary has and the second dictionary has, but the following numbers are different, then the output * then output the word with the same page number.
If the two dictionaries are exactly the same, output no changes
Note that there will be a blank line after each set of case output!
Analysis: is a brain-free simulation, not explained can also understand
#include <iostream>#include<string>#include<map>using namespaceStd;map<string,string>S1;map<string,string>S2;map<string,string>:: iterator it;stringaa[ the];voidPrintCharCintN) {cout<<c<<aa[0]; for(intI=1; i<n;i++) {cout<<","<<Aa[i]; } cout<<Endl;}intMain () {stringstr1; stringstr2; intT; CIN>>T; while(t--) {s1.clear (); S2.clear (); CIN>>str1; intn=str1.size (); CIN>>str2; intm=str2.size (); stringb; for(intI=1;i<N;) {a=""; while(str1[i]!=':'&&str1[i]!='}') A+=str1[i++]; if(str1[i]=='}') Break; I++; b=""; while(str1[i]!=','&&str1[i]!='}') b+=str1[i++]; S1[a]=b; I++; } for(intI=1;i<m;) {a=""; while(str2[i]!=':'&&str2[i]!='}') A+=str2[i++]; if(str2[i]=='}') Break; I++; b=""; while(str2[i]!=','&&str2[i]!='}') b+=str2[i++]; S2[a]=b; I++; } intc1=0, c2=0, c3=0; for(It=s2.begin (); It!=s2.end (); it++) { if(!s1.count (it->First )) AA[C1++]=it->First ; } if(c1) Print ('+', C1); for(It=s1.begin (); It!=s1.end (); it++) { if(!s2.count (it->First )) AA[C2++]=it->First ; } if(C2) print ('-', C2); for(It=s2.begin (); It!=s2.end (); it++) { if(S1.count (It->first) &&s1[it->first]!=it->second) aa[c3++]=it->First ; } if(C3) Print ('*', C3); if(c1+c2+c3==0) cout<<"No Changes"<<Endl; cout<<Endl; } return 0;}
Hunan Province University student Program design contest original question C