Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

你能帮我看一下吗? 对照你的数据,有几个输出为afer 15 .....其他都正确,到底是哪里出问题了啊

Posted by zhouronghua at 2010-03-26 20:57:51 on Problem 1016
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator