| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不明原因wa,前面有的点都过了。。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator