简单题,找不同, 用map存储dictionary就行了
要注意的是value虽然是数字, 但不定长, 因此也需要用string类型来存储
这题写得有点丑.. 仅供娱乐
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <cassert>
#include <iomanip>
using namespace std;
const int MAXN = 100+100;
typedef long long LL;
/*
uva 12504
*/
map<string,string> dic;
map<string,bool> mark;
vector<string> newk, removed, changed;
char input[MAXN];
void initial(){
dic.clear();
mark.clear();
memset(input,0,sizeof(input));
newk.clear();
removed.clear();
changed.clear();
return ;
}
void output(vector<string> & vec,char ch){
if( vec.empty() ) return ;
sort(vec.begin(),vec.end());
cout << ch << vec[0];
for(int i=1; i<vec.size(); i++){
cout << "," << vec[i];
}
cout << endl;
}
int main(){
int T;
// freopen("input2.txt","r",stdin);
scanf("%d ",&T);
while( T-- ){
initial();
gets(input);
char * ptr = input+1;
int len = strlen(input);
string key;
for(int i=1; i<len; i++){
if( input[i]==':' ){
input[i] = '\0';
if( strlen(ptr) ) key = ptr;
ptr = (input+i+1);
}else if( input[i]==',' || input[i]=='}'){
input[i] = '\0';
if( strlen(ptr) ){
dic[key] = string(ptr);
mark[key] = true;
}
ptr = (input+i+1);
}
}
gets(input);
len = strlen(input);
ptr = input+1;
for(int i=1; i<len; i++){
if( input[i]==':' ){
input[i] = '\0';
if( strlen(ptr) ) key = ptr;
ptr = (input+i+1);
}else if( input[i]==',' || input[i]=='}'){
input[i] = '\0';
if( !mark[key] && strlen(ptr) ){
newk.push_back(key);
}else if( strlen(ptr) ){
mark[key] = false; // 把1有2也有的再次标记为false, 以便后面检查removed
string value = ptr;
if( dic[key]!=value ){
changed.push_back(key);
}
}
ptr = (input+i+1);
}
}
map<string,bool>::iterator it = mark.begin();
while( it!=mark.end() ){
if( it->second==true ){
removed.push_back(it->first);
}
it++;
}
if( newk.empty() && removed.empty() && changed.empty() ){
cout << "No changes" << endl;
}else{
output(newk,'+');
output(removed,'-');
output(changed,'*');
}
cout << endl;
}
return 0;
}