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

求高手帮忙,不知为何 总是runtime error!感激不尽!!!!(附程序)

Posted by bingling at 2004-10-03 03:46:42 on Problem 1145
#include<stdio.h>
#include<string.h>
char in[1000][100];
int x,j;
int number()
{
	int n=0,t=1;
	if(in[j][x]=='-')
	{
		t=0;
		x++;
	}
	while (in[j][x]<='9'&&in[j][x]>='0')
		n=n*10+in[j][x++]-'0';
	if (t==0)
		n=-n;
	return n;
}
int check()
{
	int n,left=0,sum=0,no[1000][3],i=0,s1,s2,s3;
	char c;
	x=0;
	n=number();
	j++;
	do
	{
		x=0;
		while((c=in[j][x++])!='\0')
		{
		if(c>='0'&&c<='9'||c=='-')
			{
				x--;
				no[i][0]=number();
				no[i][1]=-1;
				no[i][2]=-1;
				sum+=no[i][0];
				if(i>0)
					if(no[i-1][1]<0)
						no[i-1][1]=1;
					else  no[i-1][2]=1;
				i++;
				s1=s2;
				s2=s3;
				s3=0;
			}
			else
				if(c=='(')
				{
					left++;
					s1=s2;
					s2=s3;
					s3=1;
				}
				else
					if(c==')')
					{
						if(s3==1)
							if(no[i-1][1]==-1)
								no[i-1][1]=0;
							else
								no[i-1][2]=0;
						left--;
						if(s1==1&&s2==-1&&s3==1)
							if(sum==n)
							{
								while(left!=0)
								{
									c=in[j][x++];
									if(c=='(')
										left++;
									else
										if(c==')')
											left--;
										else
											if(c=='\0'&&left!=0)
											{
												j++;
												x=0;
											}
								}
								j++;
								return 1;
							}
						if(no[i-1][1]==0&&no[i-1][2]==0)
						{
							sum-=no[i-1][0];
							i--;
							if(no[i-1][1]==1)
								no[i-1][1]=0;
							else
								no[i-1][2]=0;
						}
						s1=s2;
						s2=s3;
						s3=-1;
					}
		}
		j++;
	}
	while(left!=0);
	return 0;
}
main()
{
	int i=0,t,out[1000],z;
	z=scanf("%s",in[i++]);
	while(z>0)
		z=scanf("%s",in[i++]);
	for(t=0;j<i-1;)
		out[t++]=check();
	for(i=0;i<t;i++)
		if(out[i]==1)
			printf("yes\n");
		else
			printf("no\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