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,请高手帮帮我,代码如下

Posted by BadNicky at 2005-10-26 15:58:39 on Problem 2372
#include <stdio.h>
bool wrong(char c)
{
	if(c=='='||c=='+'||c=='-'||c=='*'||c=='/'||(c<58&&c>47)||c=='('||c==')')
		return false;
	else
		return true;
}

int main()
{
	char s[10000],c,ss[10000];
	int l=0,zs_start,i,j,stack;
	while(1==scanf("%c",&c))
	{
		if(c!='\n')
		{
			s[l]=c;
			l++;
		}
	}
	ss[0]=s[0];
	zs_start=0;
	for(i=1,j=1;i<l;i++,j++)
	{
		ss[j]=s[i];
		if(!zs_start&&s[i-1]=='('&&s[i]=='*')
		{
			zs_start=i;
			continue;
		}
		if(zs_start&&s[i]==')'&&s[i-1]=='*'&&i>zs_start+1)
		{
			j-=i-zs_start+2;
			zs_start=0;
		}
	}
	l=j;
	stack=0;
	for(i=0;i<l;i++)
	{
		//	printf("%c",ss[i]);
		if(ss[i]=='(')
			stack++;
		else
		{
			if(ss[i]==')')
				stack--;
			if(stack<0)
				break;
		}
		if(stack)
			if(	wrong(ss[i]) )
				break;
	}
	if(stack)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

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