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 pketm at 2010-06-06 23:10:19 on Problem 1690
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

char c[1000];
string str;

void drop(int x)
{
	int kh = 0, i;
	for (i = x+1; i < str.length(); i++)
	{
		if (str[i] == '(') kh++;
		if (str[i] == ')')
		{
			if (kh > 0) kh--;
			else
			{
				str.erase(i, 1);
				break;
			}
		}
	}
	str.erase(x, 1);
}

int main()
{
	int T;
	cin>>T;
	gets(c);
	while (T--)
	{
		gets(c);
		str = c;
		int i;
		for (i = 0; i < str.length(); i++)
			while (i < str.length() && str[i] == ' ')
				str.erase(i, 1);
		while (str[0] == '(') drop(0);
		for (i = 1; i < str.length(); i++)
		{
			if (str[i] == '+')
				while (str[i+1] == '(') drop(i+1);
			while (str[i-1] == '(' && str[i+1] == ')')
			{
				drop(i-1);
				i--;
			}
		}
		cout<<str<<endl;
	}
}

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