您的位置:首页 > 其它

NYoj 2 括号配对问题

2014-04-07 19:19 246 查看
题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=2

这个题,让我做的非常不爽!恶心!

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN = 10010;

int main()
{
char str[MAXN];
int top, T, Len, i;
scanf("%d", &T);
while(T--)
{
scanf("%s", str);
Len = strlen(str);
if(Len % 2)
{
printf("No\n");
continue ;
}
top = 0;
for(i = 1; i < Len; ++i)
{
if((str[top] == '(' && str[i] == ')') || (str[top] == '[' && str[i] == ']'))
--top;
else
str[++top] = str[i];
}
if(top == -1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: