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

我的程序已经反复检查了,就是WA,请各位大虾指点迷津,小女感激不尽

Posted by jane at 2005-05-15 11:43:05 on Problem 1016
#include<iostream.h>
#include<string.h>
void change(char *a,int *n,char *b)
{
	int i,d,j;
	for(i=0;a[i]!='\0';i++)
	{
		d=a[i]-48;
		n[d]++;
	}
	j=0;
	for(i=0;i<10;i++)
	{
		if(n[i]>0&&n[i]<10)
		{
			b[j++]=n[i]+48;
			b[j++]=i+48;
		}
		else if(n[i]>=10)
		{
			b[j++]=n[i]/10+48;
			b[j++]=n[i]%10+48;
			b[j++]=i+48;
		}
	}
	b[j]='\0';
}
int main()
{
	int num[10],i,j;
	char dig[81],temp[20][100];
	do{
		cin>>dig;
		if(dig[0]=='-')
			break;
		strcpy(temp[0],dig);
		i=0;
		while(i<16)
		{
			for(j=0;j<10;j++)
				num[j]=0;
			change(temp[i],num,temp[i+1]);
			if(strcmp(temp[i],temp[i+1])==0)
			{
				if(i==0)
					cout<<dig<<" is self-inventorying"<<endl;
				else if(i==1)
					cout<<dig<<" is self-inventorying after "<<i<<" step\n";
				else
					cout<<dig<<" is self-inventorying after "<<i<<" steps\n";
				break;
			}
			else 
			{
				for(j=0;j<i;j++)
				{
					if(strcmp(temp[i+1],temp[j])==0)
					{
						cout<<dig<<" enters an inventory loop of length "<<i+1-j<<endl;
						break;
					}
				}
				if(j<i)
					break;
			}
			i++;

		}
		if(i==16)
			cout<<dig<<" can not be classified after 15 iterations\n";
	}while(1);
	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