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 |
哪位高手帮忙看看啊(C代码),怎么老是WA啊??都快崩溃了.........#include<stdio.h> #include<string.h> void inventory(char *a, char *b) { int i, j, tmp[10]={0}; for(i=0; i<strlen(b); i++) tmp[b[i]-'0']++; for(i=0, j=0; i<10; i++) { if(tmp[i]>0) { if(tmp[i]>=10) a[j++]=tmp[i]/10+'0'; a[j++]=tmp[i]%10+'0'; a[j++]=i+'0'; } } a[j]='\0'; } int main() { char num[16][100]; int i, n; while(1) { scanf("%s", num[0]); if(strcmp(num[0], "-1")==0) break; for(n=0; n<15; n++) { inventory(num[n+1], num[n]); if(strcmp(num[n+1], num[n])==0) { if(n==0) printf("%s is self-inventorying\n", num[0]); else printf("%s is self-inventorying after %d steps\n", num[0], n); break; } else { for(i=n-1; i>=0; i--) if(strcmp(num[n+1], num[i])==0) break; if(i>=0) { printf("%s enters an inventory loop of length %d\n", num[0], n+1-i); break; } } } if(n==15) printf("%s can not be calssified after 15 iterations\n", num[0]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator