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,但是真不知道错在哪里了.. #define MAX 100 #include <stdio.h> #include <stdlib.h> #include <string.h> void deal_input(char*s); int charcmp(const void*a,const void*b); int main(void) { char input[MAX]; while(1){ memset(input,0,sizeof(input)); scanf("%s",input); if(strcmp(input,"-1")==0) break; deal_input(input); } return 0; } int charcmp(const void*a,const void*b) { return*(char*)a> *(char*)b; } void deal_input(char*s) { char ori[MAX]; char pre[MAX]; char now[MAX]; char rec[16][MAX]; int l; int i,j; memset(ori,0,sizeof(ori)); strcpy(ori,s); memset(rec,0,sizeof(rec)); strcpy(rec[0],ori); for(i= 1;i<=15;i++){ char prec; int cnt; memset(now,0,sizeof(now)); memset(pre,0,sizeof(pre)); strcpy(pre,rec[i-1]); l= strlen(pre); prec= 0; cnt= 0; qsort(pre,l,1,charcmp); for(j= 0;j<l;j++){ if(pre[j]!=prec){ if(prec!=0){ sprintf(now+strlen(now),"%d%c",cnt,prec); } prec= pre[j]; cnt= 1; }else{ cnt++; } } sprintf(now+strlen(now),"%d%c",cnt,prec); strcpy(rec[i],now); if(strcmp(now,rec[i-1])==0){ if(i==1) printf("%s is self-inventorying\n",s); else printf("%s is self-inventorying after %d steps\n",s,i-1); return; } for(j= i-2;j>=0;j--){ if(strcmp(now,rec[j])==0){ printf("%s enters an inventory loop of length %d\n",s,i-j); return; } } } printf("%s can not be classified after 15 iterations\n",s); return; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator