传送门:UVA-12504
相比于前两个STL的题,这题水多了。。。
AC代码:
#include<iostream>
#include<map>
#include<vector>
#include<sstream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--){
string tmp1,tmp2,f1,f2;
cin>>tmp1>>tmp2;
map<string,string> p1,p2;//存两个字典
//将键值对用空格分隔
for(int i=0;i<tmp1.size();++i) if(!(isalpha(tmp1[i])||tmp1[i]>='0'&&tmp1[i]<='9')) tmp1[i]=' ';
for(int i=0;i<tmp2.size();++i) if(!(isalpha(tmp2[i])||tmp2[i]>='0'&&tmp2[i]<='9')) tmp2[i]=' ';
stringstream ss1(tmp1),ss2(tmp2);
while(ss1>>f1>>f2) p1[f1]=f2;
while(ss2>>f1>>f2) p2[f1]=f2;
int cnt1=0,cnt2=0,cnt3=0;//分别代表三种情况的个数
for(map<string,string>::iterator it=p2.begin();it!=p2.end();++it)
if(!p1.count(it->first)){
if(!(cnt1++)) cout<<"+"<<it->first;
else cout<<","<<it->first;
}
if(cnt1) cout<<endl;
for(map<string,string>::iterator it=p1.begin();it!=p1.end();++it)
if(!p2.count(it->first)){
if(!(cnt2++)) cout<<"-"<<it->first;
else cout<<","<<it->first;
}
if(cnt2) cout<<endl;
for(map<string,string>::iterator it=p2.begin();it!=p2.end();++it)
if(p1.count(it->first)&&p1[it->first]!=it->second){
if(!(cnt3++)) cout<<"*"<<it->first;
else cout<<","<<it->first;
}
if(cnt3) cout<<endl;
if(!cnt1&&!cnt2&&!cnt3) cout<<"No changes\n";
cout<<endl;
}
return 0;
}