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

hawk,能不能帮我看看,我的问题到底在哪?我自己也造了一些数据进行测试,结果都是对的呀,为什么就是不能ac?

Posted by cathy1982 at 2005-04-29 16:30:43 on Problem 1016
#include<stdio.h>
#include<iostream.h>
#include<string.h>

char n[81],a[16][81];
int cop[10],inv[30];

void inventory(char *ar,char *br)
{
	int i,j,k,len;
	for(i=0;i<10;i++)
		cop[i]=0;
	for(i=0;i<30;i++)
		inv[i]=0;
	j=0;
	while(ar[j]!='\0')
	{
		cop[ar[j]-'0']++;
		j++;
	}
	j=0;
	for(k=0;k<10;k++)		
		if(cop[k]==0)
		    continue;
		else
		{
			if(cop[k]<10)
			{
				inv[j]=cop[k];
		        inv[j+1]=k;
			    j+=2;
			}
			else
			{
				inv[j]=cop[k]/10;
		        inv[j+1]=cop[k]%10;
				inv[j+2]=k;
			    j+=3;
			}
		}
	len=j;
	for(j=0;j<len;j++)
		br[j]=inv[j]+'0';		
}
void count()
{
	int i,j,step,loop;
	i=0;
	while(i<15)
	{
	   	inventory(a[i],a[i+1]);
		if(strcmp(a[i+1],a[i])==0)
			if(!i)
			{
				cout<<a[0]<<" is self-inventorying "<<endl;
				break;
			}
			else
			{
				step=i;  
				cout<<a[0]<<" is self-inventorying after "<<step<<" steps "<<endl;
				break;
			}
		else
			{
		        for(j=0;j<i;j++)
					if(strcmp(a[i+1],a[j])==0)
						{
						loop=i+1-j;
						cout<<a[0]<<" enters an inventory loop of length "<<loop<<' '<<endl;
						goto aa;
						}
				    else
						continue;
			}
		i++;		
	}
aa:	if(i==15)
		cout<<a[0]<<" can not be classified after 15 iterations "<<endl;
}
int main()
{
	int i,j,len=0;
	n[0]=getchar();
	while(n[0]!='-'&&n[0]!='0')
	{
		for(i=0;i<81;i++)
		{
			if(n[i]==' ')
			{
				i--;
                n[i+1]=getchar();
				continue;			    
			}
			else
				if(n[i]=='\n')
				{
					break;
				}
			    else
				{
					cop[n[i]-'0']++;
				    n[i+1]=getchar();
				}
		}        
		len=i;
		for(i=0;i<len;i++)
			a[0][i]=n[i];
		count();
		for(i=0;i<15;i++)
		for(j=0;j<81;j++)
			a[i][j]=NULL;
		n[0]=getchar();
	}
	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