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 |
打算放弃了,discuss里面所有的边界数据都对了,过路人有时间看一下,找到错误吼一声#include<iostream> #include<string> using namespace std; #define MAX 8100 int bitnum(int a) { int num=1; while(a/10) num++,a=a/10; return num; } int powd(int t) { int num=1; for(int i=0;i<t;i++) num*=10; return num; } char *Inventory(char *str) { char temp[MAX]; int len=strlen(str); int arr[10];//用来统计0~9的个数 memset(arr,0,10*sizeof(int)); for(int i=0;i<len;i++) arr[int(str[i]-'0')]++; int j=0; for(int i=0;i<10;i++) { if(arr[i]!=0) { int num=bitnum(arr[i]); while(num) { num--; temp[j++]=char('0'+arr[i]/powd(num)); arr[i]=arr[i]%powd(num); } temp[j++]=char('0'+i); } } temp[j]='\0'; return temp; } int main() { char str[MAX]; char strtemp[MAX]; char temp[170][MAX]; while(cin>>str) { if(strcmp(str,"-1")==0) break; int total=1; strcpy(strtemp,str); strcpy(temp[0],str); bool flag=false; while(total<=15) { strcpy(temp[total],Inventory(strtemp)); if(total==1&&strcmp(temp[total],str)==0) { flag=true; cout<<str<<" is self-inventorying"<<endl; break; } if(strcmp(temp[total-1],temp[total])==0) { flag=true; cout<<str<<" is self-inventorying after "<<total-1<<" steps"<<endl; break; } for(int i=1;i<total;i++) { if(strcmp(temp[i],temp[total])==0) { flag=true; cout<<str<<" enters an inventory loop of length "<<total-i<<endl; break; } } if(flag) break; strcpy(strtemp,temp[total]); total++; } if(!flag) cout<<str<<" can not be classified after 15 iterations"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator