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,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(a[i]%3!=sum%3) { i++; if(i==len) { m=1; while(1) { while(a[m]=='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<len) { 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(a[i]%3!=sum%3) { i++; if(i==len) { while(strcmp(a,"5")) { for(j=1;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; } } cout<<"impossible"<<endl; return 1; } } for(j=i;j<len;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