UVA 673 (暑假-线性表 -A - Parentheses Balance)

来源:互联网 发布:物理实验室软件下载 编辑:程序博客网 时间:2024/06/06 03:02
#include <cstdio>#include <stack>#include <cstring>using namespace std;int main() {int n;scanf("%d", &n);getchar();while (n--) {char str[200];gets(str);int len = strlen(str);stack<char> s;for (int i = 0; i < len; i++) {if (s.empty() && str[i] != '(' && str[i] != '[') {s.push(str[i]);break;}if (str[i] != ')' && str[i] != ']')s.push(str[i]);else if (str[i] == ')') {if (s.top() != '(')break;elses.pop();}else {if (s.top() != '[')break;elses.pop();}}if (!s.empty())printf("No\n");elseprintf("Yes\n");}return 0;}

0 0