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 |
你能帮我看一下吗? 对照你的数据,有几个输出为afer 15 .....其他都正确,到底是哪里出问题了啊In Reply To:终于过了 Posted by:hldyxh at 2008-07-30 13:46:42 #include <iostream> #include <cstdio> #include <string> using namespace std; string n; void invent(string m,int count) { string x=m,snum; char temp[3] ; int i,j,a[10]={0}; for(i=0;i<x.length();i++) { a[x[i]-48]++; } for(j=0;j<10;j++) { if(a[j]) { sprintf(temp,"%d",a[j]);//°Ñ½á¹û´æµ½ snum ÖÐÈ¥ snum.append(temp); sprintf(temp,"%d",j); snum.append(temp); } } if(snum==n||snum==x) { if(n==snum&&count==1) cout<<n<<" is self-inventorying"<<endl; if(x==snum&&count>1) cout<<n<<" is self-inventorying after "<<count-1<<" steps"<<endl; if(n==snum&&count>1) cout<<n<<" enters an inventory loop of length "<<count<<endl; } else if(count<16) invent(snum,count+1); if(count==16) cout<<n<<" can not be classified after 15 iterations "<<endl; } int main() { cin>>n; while(n!="-1") { invent(n,1); cin>>n; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator