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 00400000 at 2005-04-29 11:45:52 on Problem 1013
#include<iostream.h>
#include<stdio.h>
void main()
{
	int n,i,j,k,le,righ;
	char coins[13]="ABCDEFGHIJKL";
	char left[3][5],right[3][5],* state[3];
	char * a[2]={"hevay","light"};
	for(i=0;i<3;i++)
		state[i]=new char[5];
	scanf("%d",&n);
	while(1)
	{
		if(n==0)
			break;
		while(1)
		{
			scanf("%s %s %s",left[0],right[0],state[0]);
			scanf("%s %s %s",left[1],right[1],state[1]);
			scanf("%s %s %s",left[2],right[2],state[2]);
			for(i=0,k=0;k<12;)
			{
				if(i==3)
				{
					i=-1;
					break;
				}
				le=0;
			    righ=0;
				for(j=0;j<4;j++)
				{
					if(left[i][j]==coins[k])
						le=1;
					if(right[i][j]==coins[k])
						righ=1;
					if(le==1&&righ==1)
						break;
				}
				if(le==righ&&state[i][0]=='e')
				{
					i++;
					continue;
				}
				else if(le>righ&&state[i][0]=='u')
				{
					i++;
					continue;
				}
				else if(le<righ&&state[i][0]=='d')
				{
					i++;
					continue;
				}
				else
				{
					i=0;
					while(1)
					{
						if(i==3)
						{
							j=-1;
							break;
						}
						le=1;
						righ=1;
						for(j=0;j<4;j++)
						{
							if(left[i][j]==coins[k])
								le=0;
							if(right[i][j]==coins[k])
								righ=0;
							if(le==0&&righ==0)
								break;
						}
						if(le==righ&&state[i][0]=='e')
						{
							i++;
							continue;
						}
						else if(le>righ&&state[i][0]=='u')
						{
							i++;
							continue;
						}
						else if(le<righ&&state[i][0]=='d')
						{
							i++;
							continue;
						}
						else
						{
							i=0;
							k++;
							break;
						}
					}
				}
				if(j==-1)
					break;
			}
			if(i==-1||j==-1)
				break;
		}
		if(i==-1)
		{
			printf("%c",coins[k]);
			printf(" is the counterfeit coin and it is ");
			printf("%s",a[0]);
			printf(".\n");
		}
		if(j==-1)
		{
			printf("%c",coins[k]);
			printf(" is the counterfeit coin and it is ");
			printf("%s",a[1]);
			printf(".\n");
		}
		n--;
	}
}



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