您的位置:首页 > 其它

UVa 673 - Parentheses Balance

2014-05-02 16:43 417 查看
传送门UVa 673 - Parentheses Balance

题意是判断括号是否合法. 

水题.

回想起两个月前我第一次看到这种题目时想的那个绞尽脑汁啊......最后还TLE了╮(╯▽╰)╭

UVa挂了, 先贴代码. 应该没错.

-------------------------------------------------------------------------------------------------------------

AC.



#include <cstdio>
#include <stack>
using namespace std;

int main()
{
//freopen("input.txt", "r", stdin);
stack<char> in;
int n;
char c;
scanf("%d", &n);
getchar();
while (n--)
{
while ((c = getchar()) != '\n')
{
if (!in.empty())
{
if (c == ']' && in.top() == '[' || c == ')' && in.top() == '(')
in.pop();
else
in.push(c);
}
else
in.push(c);
}
if (in.empty())
printf("Yes\n");
else
printf("No\n");
while (!in.empty())
in.pop();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM UVa