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 |
这里边的所有测试数据都通过了,还是WA,哪位看下哪错了,给些测试数据!#include <iostream> #include <algorithm> using namespace std; int main() { char a[1010],c; int i,j,k,m,len,sum; cin>>a; len=strlen(a); sort(a,a+len); if(a[0]=='0') { i=0; sum=0; while(i<len) { sum=sum+(int)(a[i]-'0'); i++; } if(sum%3==0) { if(sum!=0) { for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } else { cout<<"0"<<endl; return 1; } } else { i=1; while(((int)(a[i]-'0'))%3!=sum%3) { i++; if(i==len) { m=1; while(1) { while(((int)(a[m]-'0'))%3==0) m++; for(j=m;j<strlen(a);j++) a[j]=a[j+1]; i=0; sum=0; while(i<strlen(a)) { sum=sum+(int)(a[i]-'0'); i++; } if(sum%3==0) { if(sum==0) { cout<<"0"<<endl; return 1; } for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } } } } for(j=i;j<len;j++) a[j]=a[j+1]; i=0; sum=0; while(i<strlen(a)) { sum=sum+(int)(a[i]-'0'); i++; } if(sum==0) { cout<<"0"<<endl; return 1; } for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } } else { i=0; while(a[i]!='5') { i++; if(i==len) { cout<<"impossible"<<endl; return 0; } } if(i!=0) { c=a[i]; a[i]=a[0]; a[0]=c; } sort(a+1,a+len); i=0; sum=0; while(i<strlen(a)) { sum=sum+(int)(a[i]-'0'); i++; } if(sum%3==0) { for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } else { i=1; while(((int)(a[i]-'0'))%3!=sum%3) { i++; m=1; k=0; if(i==len) { while(((int)(a[m]-'0'))%3==0||((int)(a[m]-'0')%3==5%3)) { if((int)(a[m]-'0')%3==5%3) k++; m++; if(m==strlen(a)) break; } if(k==1) { cout<<"impossible"<<endl; return 1; } m=1; while(1) { while(((int)(a[m]-'0'))%3==0) { m++; if(m==strlen(a)) break; } for(j=m;j<strlen(a);j++) { a[j]=a[j+1]; } i=0; sum=0; while(i<strlen(a)) { sum=sum+(int)(a[i]-'0'); i++; } if(sum%3==0) { for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } } } } for(j=i;j<strlen(a);j++) a[j]=a[j+1]; for(j=strlen(a)-1;j>=0;j--) cout<<a[j]; cout<<endl; return 1; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator