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,麻烦高人看一下代码,是哪里的问题代码如下: #include <iostream> using namespace std; int cmp(char* p1 ,char* p2){//比较两个char型数组是否相等,0——不等,1——相等 while((*p1) !='\0') { if ((*p2) !='\0') { if ((*p1)==(*p2)) { p1++; p2++; } else { return 0; } } else { return 0; } } if ((*p2)=='\0') { return 0; } return 1; } int main(){ char digit[81]; char first[81]; char temp[81]; int dc[10]; int i; int j; int num; while(1){ cin>>digit; if ('-'== digit[0]) { return 0; } num=0; while(num<14){ for (j=0;j<10;j++)dc[j]=0; if (num==0) { j=0; while(digit[j]!='\0'){ temp[j]=digit[j]; j++; } temp[j]='\0'; } j=0; while(temp[j]!='\0'){//统计0到9的个数 switch(temp[j]){ case '0':dc[0]++;break; case '1':dc[1]++;break; case '2':dc[2]++;break; case '3':dc[3]++;break; case '4':dc[4]++;break; case '5':dc[5]++;break; case '6':dc[6]++;break; case '7':dc[7]++;break; case '8':dc[8]++;break; case '9':dc[9]++;break; default:break; } j++; }//while(temp[j]!='\0') is over i=0; for (j=0;j<9;j++){//转换为char型数组。11要转换成两个1, if (dc[j]<=9 && dc[j]>0){ //cout<<dc[j]; temp[i]=dc[j]+48; i++; //cout<<j+1; temp[i]=j+48; i++; }else{ if (dc[j]>9) { temp[i]=dc[j]/10+48; i++; temp[i]=dc[j]%10+48; i++; temp[i]=j+48; i++; } } }//for (j=0;j<9;j++) is over temp[i]= '\0'; if (num==0) { while(i>=0){ first[i]=temp[i];//first[]数组保留第一次转换的结果 i--; } }//if(num==0) is over if (1==cmp(temp,digit)) { if (num==0) { cout<<digit; cout<<" is self-inventorying"<<endl; break; } else { cout<<digit; cout<<" is self-inventorying after "<<num+1<<" steps"<<endl; break; } } if (1==cmp(temp,first)) { if (num!=0) { cout<<digit; cout<<" enters an inventory loop of length "<<num+1<<endl; break; } } num++; }//while(num<14) is over if (num==14)//15次以上,不考虑了。 { cout<<digit; cout<<" can not be classified after 15 iterations"<<endl; } }//while(1) is over return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator