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 |
Help! I got WA but I don't know why....#include<stdio.h> char str[1010]; int a[1010]; int len; int cmp(const void *a,const void *b) { return *((int *)a)-*((int *)b); } int solve(int rem) { int i,j; for(i=2;i<=len;i++){ if(a[i]%3==rem){ for(j=i+1;j<=len;j++) a[j-1]=a[j]; len--; return 1; } } return 0; } int main() { int i,j,k,rem; int no=0,sum=0; gets(str); len=strlen(str); for(i=0;i<len;i++){ a[i+1]=str[i]-'0'; sum+=a[i+1]; } qsort(a+1,len,sizeof(int),cmp); if(a[1]!=0){ for(i=2;i<=len;i++) { if(a[i]==5){ for(j=i-1;j>=1;j--) a[j+1]=a[j]; a[1]=5; break; } } if(i>len) no=1; } rem=sum%3; if(rem!=0){ if(solve(rem)==0){ if(solve(3-rem)==0) no=1; if(solve(3-rem)==0) no=1; } } if(no==1) printf("impossible\n"); else{ while(len>1&&a[len]==0) len--; for(;len>=1;len--) printf("%d",a[len]);printf("\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator