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

HELP,都能通过就是WRONGANSWER,大家帮个忙吧,多谢

Posted by 00448087 at 2005-03-17 21:12:59 on Problem 1016
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
//如何实现变换
void change(char[]);char *jk=NULL ;
char inh[100]; //char*temp[19]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int bji=1,x=1;//函数调用次数
char *temp[19];
int go=0;
void main() 
{	
  
  	  cin>>inh;
	  while(!(inh[0]=='-'))
	  { bji=1;
		change(inh);
		go=0;
		 for(int i=0;i<100;i++)
			 inh[i]=0;
		// for(i=0;i<19;i++)
		//	 temp[i]=0;
		 for(int g=0;g<19;g++)
    temp[g]= new char[15];
		cin>>inh;
		x=1;
		//cout<<inh;	
	  }
	  
		  
}

void change( char h[])//change(tok);
{/*jk=tok;
			 temp[0]=inh;
			 temp[x++]=jk;*/

	
	temp[0]=inh;
    int token[9]={0};
	for(int i=0;h[i]!=0;i++)
	{
		switch(h[i])
		{
		case '1':token[0]++;break;

		case '2':token[1]++;break;
		case '3':token[2]++;break;
		case '4':token[3]++;break;
		case '5':token[4]++;break;
		case '6':token[5]++;break;
		case '7':token[6]++;break;
		case '8':token[7]++;break;
		case '9':token[8]++;break;
		}
	}
//转换后输出,仅是个数在10以内的情况
char tok[100]={NULL};int p=0;//int token[];
	for(i=0;i<9;i++)
	{//yi wei shu qing kuang
		int pivot=token[i]/10;
		if(token[i]!=0&&token[i]/10==0){
		tok[p++]=token[i]+'0';
		tok[p++]=i+1+'0';//i+1 bu hui chao xian
		}
		if(pivot>=1&&pivot<10){//两位数
		tok[p++]=pivot+'0';
		tok[p++]=token[i]%10+'0';
		tok[p++]=i+1+'0';
	 
		}
	}
	
	temp[x++]=tok;
	//	cout<<tok<<endl;
		if(!strcmp(tok,inh)&&bji==1)cout<<inh<<" is self-inventorying "
			<<endl; 
	else if(!strcmp(tok,h)&&bji>1)cout<<inh<<" is self-inventorying after " 
			<<bji-1<<" steps"<<endl;
		else if(bji>1)
		{
			for(i=0;i<(x-2);i++){
				if(!strcmp(temp[i],tok))
				{//?比较对象调整
					cout<<inh<<" enters an inventory loop of length "
					<<bji-i
					<<endl;
					go=12;
					break;
				}
			}
			if(go==0)
			goto P;
		
		}
			else 
		{
			 P:
			 bji++;
			 if(bji==16)
			 {cout<<inh
			      <<" can not be classified after 15 iterations" 
				  <<endl;
				 goto Loop;
			 }
			 jk=tok;
			 //temp[0]=inh;
			 //temp[x++]=jk;
			 //strcpy(temp[0],inh);//??
			 //strcpy(temp[x++],jk);//x=1;CHUZHI
			 change(jk);
		}
Loop:;
}

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