湖南省第八屆大學生電腦程式設計競賽C題(UVA 12504)

來源:互聯網
上載者:User

題目連結:點擊開啟連結

#include <iostream>#include <map>#include <string>using namespace std;map <string,string> my1,my2;     //{a:3,b:4,c:10,f:6} {third:3,second:2}map <string,string>::iterator it,it2;string s1[105],s2[105],s3[105];void input(){char c; string s="";cin>>c; while(cin>>c&&c!='}'){if(c!=':'&&c!=',') s+=c;else if(c==':') {string s1="";while(cin>>c&&c!=','&&c!='}')  s1+=c;my2[s]=s1;if(c=='}') break;if(c==',') s="";}}}int main(int argc, char *argv[]){int t,i,j,k;cin>>t;  while(t--){     input();  my1=my2; my2.clear(); input(); i=j=k=0;for(it=my1.begin();it!=my1.end();it++) //減少的 {it2=my2.find(it->first); if(it2==my2.end()) s2[j++]=it->first;}for(it=my2.begin();it!=my2.end();it++){it2=my1.find(it->first);if(it2!=my1.end()&&it2->second!=it->second )  s3[k++]=it->first;//找到且不同if(it2==my1.end()) s1[i++]=it->first; //增加的 }if(i+j+k==0) cout<<"No changes"<<endl;else{   int l;if(i!=0){cout<<'+'<<s1[0]; for(l=1;l<i;l++)cout<<','<<s1[l];cout<<endl;}if(j!=0){cout<<'-'<<s2[0]; for(l=1;l<j;l++)cout<<','<<s2[l];cout<<endl;}if(k!=0) {cout<<'*'<<s3[0]; for(l=1;l<k;l++)cout<<','<<s3[l];cout<<endl;}}cout<<endl; my1.clear(); my2.clear(); }return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.