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 |
请问过路大哥,为什么会在输入多个数据,然后再输入-1结束程序时,会出现错误?当不输入数据,直接输入-1时,程序能正常结束!!感激不尽,我实在被弄的不行了。谢谢#include<stdio.h> #include<string.h> void main() { char p[16][100]; char m[10],temp[3]; int i,j,k,flag; scanf("%s",p[0]); while(strcmp(p[0], "-1")) { flag=1; for(i=0;i<=15;i++) { p[i+1][0]='\0'; for(j=0;j<10;j++) m[j]=0; for(k=0;p[i][k]!='\0';k++) m[p[i][k]-'0']++; for(j=0;j<10;j++) { if(m[j]!=0) { temp[0]=m[j]+'0'; temp[1]=j+'0'; temp[2]='\0'; strcat(p[i+1],temp); } } } if(strcmp(p[0],p[1])==0) {printf("%s is self-inventorying\n",p[0]); flag=0;} for(i=2;i<=15&&flag==1;i++) { if(strcmp(p[i],p[i-1])==0) {printf("%s is self-inventorying after %d steps\n",p[0],i-1); break;} for(k=i-1;k>=0;k--) if(strcmp(p[i],p[k])==0) {printf("%s enters an inventory loop of length %d\n",p[0],i-k);flag=0; break;} } if(i==16) printf("%s can not be classified after 15 iterations\n",p[0]); scanf("%s",p[0]); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator