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

帮我看看我的代码 ,不知道哪里不对,单步调试都是对的啊(我是新手)。

Posted by zhouronghua at 2010-03-26 20:48:29 on Problem 1016
 
#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