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 |
答案都对!为什么事runtime error 呀?!! 谁能帮帮我呀!谢了!#include <iostream.h> #include <string.h> #include <stdlib.h> char initial[91];//用以保存输入的数字 char present[91];//保存变换了一次后的数字 char next[91];//保存将present变换后的数字 char record[19][91]; //记录数字的数组 change (char[]);*/ void change (char[],char[]); //通过题述方式进行变换 int i,j,h=0; //用以记数 void main() { cin>>initial; //while(atoi(initial)>0){ //将initial数字化是不行的! 因为int是有取值范围的 while(initial[0]!='-') { h=0; char temp[91]; //接受change函数变换后的数字 strcpy(present,initial); //将present赋为initial的值 strcpy(record[h],initial); //开始进行记录 for(i=0;i<15;i++) { change(present,temp); //将temp赋为变换后的值 strcpy(next,temp);h++; strcpy(record[h],temp); for(int m=0; m<h;m++) { if(strcmp(next,record[m])==0) { if(i==0) { cout<<initial<<" is self-inventorying"<<endl; goto LOOP; } else if(h-m==1) { cout<<initial<<" is self-inventorying after " <<i<<" steps"<<endl; goto LOOP; } else { cout<<initial<<" enters an inventory loop of length "<<i-m+1<<endl; goto LOOP; } } } strcpy(present, next); } if(i==15) cout<<initial<<" can not be classified after 15 iterations"<<endl; LOOP: cin>>initial;} } void change (char present[], char temp[]) { int counter[10]={0,0,0,0,0,0,0,0,0,0}; //用counter数组保存0~9个数字出现的次数 int k; //临时记数变量 j=0; while(present[j]!='\0') //用while语句将present数组中的各个数字出现频率读出 { k=present[j]-'0'; counter[k]++; j++; } char temp2[91];//用以保存变化后的临时数组,并将其数组所有元素都赋值为字符0,因为有意义的0永远不能在最后 memset(temp2,0,sizeof(temp2)); for(j=0,k=0;j<10;j++) { if(counter[j]!=0) { if(counter[j]/10>0) { temp2[k]=(char)(counter[j]/10+'0'); k++; }//记得一定要加'0' temp2[k]=(char)(counter[j]%10+'0');k++; temp2[k]=(char)(j+'0');k++; } } temp2[k]='\0';//最后一位为结束符 strcpy(temp,temp2); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator