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 00448295 at 2005-03-19 15:38:43 on Problem 1016
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
void main()
{
	char p[81];
	char temp[31],check[81],fuck[16][81];
	int i,j,l,total,step,length;
	char bb[3]={"-1"};
	int num[10];
AD:	while(1)
	{
	cin.getline(p,81);
	if(strcmp(p,bb)==0)exit(0);
	strcpy(check,p);
	step=0,length=0,l=-1;
ED:	for(i=0;i<10;i++)
		num[i]=0;
	for(i=0;i<strlen(check);i++)
	{
		switch(check[i])
		{
		case '0':num[0]++;break;
		case '1':num[1]++;break;
		case '2':num[2]++;break;
		case '3':num[3]++;break;
		case '4':num[4]++;break;
		case '5':num[5]++;break;
		case '6':num[6]++;break;
		case '7':num[7]++;break;
		case '8':num[8]++;break;
		case '9':num[9]++;break;
		}
	};
	for(i=0;i<10;i++)total+=num[i];
	j=0;
	for(i=0;i<10;i++)
	{
		if(num[i]!=0)
		{
			if(num[i]<10)
			{
				temp[j]=num[i]+'0';
				temp[j+1]=i+'0';
				j=j+2;
			}else
			{
				temp[j]=num[i]/10+'0';
				temp[j+1]=num[i]%10+'0';
				temp[j+2]=i+'0';
				j=j+3;
			};
		}
	}
	temp[j]='\0';
	step++;
	length++;
	l++;
	strcpy(fuck[l],temp);
	
	
	if(strcmp(temp,check)==0)
	{
		if(step==1)
		cout<<p<<" is self-inventorying\n";
		else
			if(step>1&&step<16)cout<<p<<" is self-inventorying after "<<step-1<<" steps\n";
		if(step>=16)cout<<" can not be classified after 15 iterations\n";
	}
	else
	{
		
		for(i=0;i<l;i++)
		{
			if(strcmp(fuck[i],temp)==0&&strcmp(fuck[i],check)!=0)
			{
				
				cout<<p<<" enters an inventory loop of length "<<length-i-1<<endl;
				goto AD;
			}
		}
		strcpy(check,temp);
			goto ED;
	};
	}
	//cout<<temp<<endl;
}

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