水题。但还是wa了。。
注意空字符串以及最后匹配完仍有剩余的情况即可。
注意空字符串以及最后匹配完仍有剩余的情况即可。
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define LL long long
#define maxn 100005
#define maxm 1005
#define mod 1000000007
#define INF 1000000007
#define eps 1e-5
#define PI 3.1415926535898
#define N 26
using namespace std;
//-------------------------CHC------------------------------//
char in[maxn];
map<char, int> bracket;
int main() {
//IN(); OUT();
bracket['('] = 1;
bracket[')'] = -1;
bracket['['] = 2;
bracket[']'] = -2;
int T;
scanf("%d", &T); getchar();
while (T--) {
fgets(in, maxn, stdin);
stack<char> sta;
bool ok = true;
for (int i = 0; in[i] != '\n'; ++i) {
if (bracket[in[i]] > 0) sta.push(in[i]);
else {
if (sta.size()) {
char cur = sta.top(); sta.pop();
if (bracket[cur] + bracket[in[i]]) { ok = false; break; }
}
else { ok = false; break; }
}
}
if (sta.size()) ok = false;
puts(ok ? "Yes" : "No");
}
}