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 |
帮我看看我的代码 ,不知道哪里不对,单步调试都是对的啊(我是新手)。#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