Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
附上我的代码,谢谢各位大牛了In Reply To:Re:确实要判断可能性最大的那一个数据,没过的可以试试这个数据 Posted by:deliver at 2004-10-24 01:16:58 #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; void main() { // freopen("in.txt","r",stdin); int num; cin>>num; while(num--) { vector<int> vi(12,0);//初使0 真的2 可能重1 可能轻-1 string left; string right; string con; for(int i=0;i<3;i++) { cin>>left>>right>>con; int size=left.size(); if(con.compare("even")==0) for(int j=0;j<size;j++){ vi[left[j]-'A']=2; vi[right[j]-'A']=2; } else if(con.compare("up")==0) { for(int j=0;j<size;j++){ if(vi[left[j]-'A']==0) vi[left[j]-'A']=1; if(vi[left[j]-'A']==-1) vi[left[j]-'A']=2; if(vi[right[j]-'A']==0) vi[right[j]-'A']=-1; if(vi[right[j]-'A']==1) vi[right[j]-'A']=2; } int pro=0; //处理只有一个是不确定的情况,这种情况直接输出 int pos=-1; for(j=0;j<size;j++) { if(vi[left[j]-'A']!=2) { pro++; pos=left[j]-'A'; } if(vi[right[j]-'A']!=2) { pro++; pos=right[j]-'A'; } } if(pro==1) { cout<<(char)(pos+'A')<<" is the counterfeit coin and it is "<<((vi[pos]==1)?"heavy.":"light.")<<endl; goto end; } } else if(con.compare("down")==0) { for(int j=0;j<size;j++){ if(vi[left[j]-'A']==0) vi[left[j]-'A']=-1; if(vi[left[j]-'A']==1) vi[left[j]-'A']=2; if(vi[right[j]-'A']==0) vi[right[j]-'A']=1; if(vi[right[j]-'A']==-1) vi[right[j]-'A']=2; } int pro=0; //和上面的一样 int pos=-1; for(j=0;j<size;j++) { if(vi[left[j]-'A']!=2) { pro++; pos=left[j]-'A'; } if(vi[right[j]-'A']!=2) { pro++; pos=right[j]-'A'; } } if(pro==1) { cout<<(char)(pos+'A') <<" is the counterfeit coin and it is "<<((vi[pos]==1)?"heavy.":"light.")<<endl; goto end;//直接跳出 } } } vector<int>::iterator result; if((result=find(vi.begin(),vi.end(),1))!=vi.end()) cout<<(char)(distance(vi.begin(),result)+'A')<<" is the counterfeit coin and it is heavy."<<endl; else if((result=find(vi.begin(),vi.end(),-1))!=vi.end()) cout<<(char)(distance(vi.begin(),result)+'A')<<" is the counterfeit coin and it is light."<<endl; end: ; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator