题目描述:
解题思路:
1.根据:和,获得字符串
2.使用两个map进行比较;
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <map> 5 using namespace std; 6 map<string, string>::iterator it; 7 map<string,string> dict[2]; 8 string str[105]; 9 int main(int argc, char *argv[]) 10 { 11 int t ; 12 cin >> t; 13 while(t--) 14 { 15 dict[0].clear(), dict[1].clear(); 16 for(int i=0;i<2;i++) 17 { 18 string s,t1,t2; 19 cin >> s ; 20 int j=1,len = s.size() ; 21 while(j < len && len > 2) 22 { 23 while(s[j]!=‘:‘) t1 += s[j++] ; ++j ; 24 while(s[j]!=‘,‘ && s[j]!=‘}‘) t2 += s[j++] ; ++j ; 25 dict[i][t1] = t2 ; 26 t1 = t2 = "" ; 27 } 28 } 29 int a=0,s=0,m=0; 30 for(it=dict[1].begin();it != dict[1].end();it++) 31 if(!dict[0].count(it->first)) str[a++] = it->first; 32 if(a) 33 { 34 sort(str,str+a); 35 cout << "+" << str[0] ; 36 for(int i = 1; i < a; ++i) cout << ‘,‘ << str[i]; 37 puts(""); 38 } 39 for(it=dict[0].begin();it != dict[0].end();it++) 40 if(!dict[1].count(it->first)) str[s++] = it->first; 41 if(s) 42 { 43 sort(str,str+s); 44 cout << "-" << str[0] ; 45 for(int i = 1; i < s; ++i) cout << ‘,‘ << str[i]; 46 puts(""); 47 } 48 for(it=dict[1].begin();it != dict[1].end();it++) 49 if(dict[0].count(it->first)&&dict[0][it->first] != it->second) str[m++] = it->first; 50 if(m) 51 { 52 sort(str,str+m); 53 cout << "*" << str[0] ; 54 for(int i = 1; i < m; ++i) cout << ‘,‘ << str[i]; 55 puts(""); 56 } 57 if(!(a || s || m)) puts("No changes"); 58 puts(""); 59 } 60 return 0; 61 }
原文地址:https://www.cnblogs.com/secoding/p/9495592.html
时间: 2024-11-06 09:32:40