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 U2007 at 2007-05-24 22:04:58 on Problem 1016
#include <string>
#include <iostream>
using namespace std;

string fun(string n)
{	
	int c[10]={0,0,0,0,0,0,0,0,0,0};
	int i,j;
	string res;
	for( i=0; i < n.length();i++)
	{
		for(j=0;j<10;++j)
		{
			if(j==(int)n[i]-48)
			{
				c[j]=c[j]+1;
			}
		}
	}
	for(i=0;i<10;i++)
	{
		if(c[i]>0)
		{
			res=res+(char)(c[i]+48)+(char)(i+48);
		}
	}
	return res;
} 
int main()
{	
	string s,a;
	string b[16];
	
	while (cin >> s && s!="-1")
	{
		int i=0,j=0;
		int p=1;

		b[0]=s;
		for (i=1; i<16; i++)
		{
			s = fun(s);
			b[i] = s;
		}
		for (i=0; i<16&&p==1; i++)
		{
			for (j=i; j<=16; j++)
			{
				if (b[i]==b[j+1])
				{
					p = 0;
					break ;
				}
			}
		}
		i--;
		j++;
	
cout << i << "   " << j << endl;
			
		if (i==0&&j==1)
		{
			cout << b[0] << " is self-inventorying" << endl;
		}
		if (i!=0&&j==i+1)
		{
			cout << b[0] << " is self-inventorying after " << i << " steps" << endl;
		}
		if (i<=14&&j<=14&&(j-i)>1)
		{
			cout << b[0] << " enters an inventory loop of length " << j-i << endl;
		}
		if (i>=15)
		{
			cout << b[0] << " can not be classified after 15 iterations" << endl;
		} 
	}

	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