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, thanks

Posted by Jayida at 2004-07-25 17:16:58 on Problem 1706
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char description[4000][241];
int description_id[4000];
int description_num;
int transfer[4000];
int transfer_num;
int current_count;
int index[4000];
int weishu(int i)
{
	int count=0;
	while(1)
	{
		count++;
		i/=10;
		if(i==0) break;
	}
	return count;
}
int ifemptyline(char *string)
{
	int i;
	for(i=0;i<strlen(string);i++)
		if(string[i]!=' '&&string[i]!='\n')
			return 0;
	return 1;
}


void replace(char *string,int start,int end,int k)
{
	char temp[241];
	_itoa(k,temp,10);
	strcat(temp,&string[end]);
	string[start+1]='\0';
	strcat(string,temp);
}

int main()
{



	char line[81];
	transfer_num=description_num=current_count=0;
	int i,j;
	int thenum;
	int start;
	int end=0;
	int flag=0;//?TDè′òó???DD
	memset(description,'\0',sizeof(char)*4000*241);	
    
 	int F;
	while(end||gets(line)!=NULL)
	{	
		F=0;
		while(ifemptyline(line))
		{//1y????DD
			F=1;
			if(gets(line)==NULL)
			{ 
			   end=1;
			   F=0;
		       break;
			}
		}
		if(end==1) break;
	    if(F&&flag) printf("\n");
		i=0;
		while(i<strlen(line))
		{
			if(line[i]=='[')
			{
				start=i;
				i++;
				thenum=0;
				while(line[i]!=']')
				{
					if(line[i]>='0'&&line[i]<='9')
					{
						thenum=thenum*10+(line[i]-'0');
						i++;
					}
					else while(1);
				}
				if(start==0)
				{//Reference descriptions
					description_id[description_num]=thenum;
                   	while(!ifemptyline(line))
					{//?áè?Reference descriptions
					//	printf("%s",line);
						strcat(description[description_num],line);
					//	printf("±ê??:%s\n",line);
						memset(line,'\0',sizeof(char)*81);
						if(gets(line)==NULL)
						{ 
						   end=1;
					       break;
						}
					}
                    description_num++;
                    if(end==1) break;
					while(ifemptyline(line))
					{//1y????DD
						if(gets(line)==NULL)
						{ 
						   end=1;
					       break;
						}
					}
					if(end==1) break;
					i=0;
					flag=0;
				}//if(start==0)
				else
				{
					int k;
					for(k=0;k<transfer_num;k++)
					{
						if(transfer[k]==thenum) break;
					}
					if(k==transfer_num)
					{
						transfer[transfer_num++]=thenum;
					}
					replace(line,start,i,k+1);
					
				}
			}//line[i]==']'
			else i++;
		}
		printf("%s",line);
		flag=1;
	}
	for(i=0;i<transfer_num;i++)
	{
		for(j=0;j<description_num;j++)
		{
			if(description_id[i]==transfer[j]) break;
		}
		index[i]=j;
	}
	printf("\n");
	for(i=0;i<transfer_num-1;i++)
	{
		replace(description[index[i]],0,weishu(description_id[index[i]])+1,i+1);
		printf("%s\n",description[index[i]]);
	}
	if(i<transfer_num)
	{
            replace(description[index[i]],0,weishu(description_id[index[i]])+1,i+1);
	   printf("%s",description[index[i]]);
	}
	
}
	



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