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 326775408 at 2011-05-16 13:22:06 on Problem 1690
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int main()////-((A+A))========
{//poj1693
	int i,j,m,num[300];
	char c,s[300];
	cin>>m;getchar();
	while (m--)
	{
		memset(num,0,sizeof(num));
		gets(s);
		int t1,t2,flag=0;
		for(i=0;s[i]!='\0';i++)
		{
		    if(num[i]==-1)continue;
			if(s[i]!='('&&s[i]!=' ')flag=1;
			if(s[i]=='('&&flag==0)
			{
				t1=1;num[i]=-1;
				for(j=i+1;s[j]!='\0';j++)
				{
					if(s[j]=='(')t1++;
					if(s[j]==')')t1--;
					if(t1==0)
					{
						num[j]=-1;break;
					}
				}
				continue;
			}
			if(s[i]=='('&&s[i-1]=='+')
			{
				t1=1;num[i]=-1;
				for(j=i+1;s[j]!='\0';j++)
				{
					if(s[j]=='(')t1++;
					if(s[j]==')')t1--;
					if(t1==0)
					{
						num[j]=-1;break;
					}
				}
				continue;
			}
			if(s[i]=='(')
			{
				t2=0;t1=1;int mm;
				for(j=i+1;s[j]!='\0';j++)
				{
					if(s[j]=='(')t1++;
					if(s[j]==')')t1--;
					if(s[j]>='A'&&s[j]<='Z')t2++;
					if(t1==0)
					{
						break;
					}
				}
				if(s[i+1]=='('&&s[j-1]==')')
				{
				    t1=1;
				    for(mm=i+2;mm<j;mm++)
				    {
				        if(s[mm]=='(')t1++;
				        if(s[mm]==')')t1--;
				        if(t1==0)break;
				    }
				    if(mm==j-1)
				    {num[i]=-1;num[j]=-1;}
				}
				if(t2==1)
				{
					t1=1;num[i]=-1;
					for(j=i+1;s[j]!='\0';j++)
					{
						if(s[j]=='(')t1++;
						if(s[j]==')')t1--;
						if(s[j]=='('||s[j]==')')
							num[j]=-1;
						if(t1==0)
						{
							break;
						}
					}
				}
			}
		}
		for(i=0;s[i]!='\0';i++)
		{
			if(s[i]==' ')continue;
			if(num[i]==-1)continue;
			cout<<s[i];
		}
		cout<<endl;
	}
	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