按题目说的来,也没合并情况,看起来有点瘦长。。大家凑合看吧~~
一开始忘了加入空集的情况,后来又加的。。。
#include<cstdio>
#include<iostream>#include<algorithm>
#include<string>
using namespace std;
int main(){
int T;
scanf("%d",&T);
while(T--){
string buf,s1[100],s2[100],s3[100],s4[100];
cin>>buf;
int kase=0,maxn=0;
while(1){
if(buf[kase]=='{'||buf[kase]==','){
kase++;
while(buf[kase]!=':'&&buf[kase]!='}'){
s1[maxn]+=buf[kase];
kase++;
}
}
if(buf[kase]==':'){
kase++;
while(buf[kase]!=','&&buf[kase]!='}'){
s2[maxn]+=buf[kase];
kase++;
}
}
maxn++;
if(buf[kase]=='}')
break;
}
cin>>buf;
kase=0;
int maxn2=0;
while(1){
if(buf[kase]=='{'||buf[kase]==','){
kase++;
while(buf[kase]!=':'&&buf[kase]!='}'){
s3[maxn2]+=buf[kase];
kase++;
}
}
if(buf[kase]==':'){
kase++;
while(buf[kase]!=','&&buf[kase]!='}'){
s4[maxn2]+=buf[kase];
kase++;
}
}
maxn2++;
if(buf[kase]=='}')
break;
}
if(s1[0].empty()&&!s3[0].empty()){
cout<<"+";
sort(s3,s3+maxn2);
for(int i=0;i<maxn2;i++)
if(i==maxn2-1)
cout<<s3[i]<<"\n\n";
else
cout<<s3[i]<<",";
continue;
}
if(!s1[0].empty()&&s3[0].empty()){
cout<<"-";
sort(s1,s1+maxn);
for(int i=0;i<maxn;i++)
if(i==maxn-1)
cout<<s1[i]<<"\n\n";
else
cout<<s1[i]<<",";
continue;
}
if(s1[0].empty()&&s3[0].empty()){
printf("No changes\n\n");
continue;
}
int cnt=0;
string s6[100];
for(int i=0;i<maxn2;i++){
int ans=0;
for(int j=0;j<maxn;j++)
if(s3[i]==s1[j]){
ans=1;break;
}
if(ans==0)
s6[cnt++]+=s3[i];
}
if(cnt>0){
cout<<"+";
sort(s6,s6+cnt);
for(int i=0;i<cnt;i++)
if(i==cnt-1)
cout<<s6[i]<<'\n';
else
cout<<s6[i]<<",";
}
string s[100],s5[100];kase=0;
int bbs=0;
for(int i=0;i<maxn;i++){
int ans=0;
for(int j=0;j<maxn2;j++){
if(s1[i]==s3[j]){
ans=1;
if(s2[i]!=s4[j])
s5[bbs++]+=s1[i];
break;
}
}
if(ans==0)
s[kase++]+=s1[i];
}
if(kase>0){
cout<<"-";
sort(s,s+kase);
for(int i=0;i<kase;i++){
if(i==kase-1)
cout<<s[i]<<'\n';
else
cout<<s[i]<<",";
}
}
if(bbs>0){
cout<<"*";
sort(s5,s5+bbs);
for(int i=0;i<bbs;i++){
if(i==bbs-1)
cout<<s5[i]<<'\n';
else
cout<<s5[i]<<",";
}
}
if(cnt==0&&bbs==0&&kase==0)
printf("No changes\n");
printf("\n");
}
return 0;
}