| 比赛 |
?板子大赛 |
评测结果 |
AWAWA |
| 题目名称 |
括号匹配 |
最终得分 |
60 |
| 用户昵称 |
赵飞羽 |
运行时间 |
0.145 s |
| 代码语言 |
C++ |
内存使用 |
4.89 MiB |
| 提交时间 |
2026-01-17 10:47:40 |
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000010;
int T, cnt, ans, sum;
string s;
stack <char> stk;
int sp(char x) {
if (x != '(' && x != ')' && x != '[' && x != ']' && x != '{' && x != '}' && x != '<' && x != '>') return 1;
return 0;
}
int z(char x) {
if (x == '(' || x == '[' || x == '{' || x == '<') return 1;
return 0;
}
int ck(char x, char y) {
if (sp(x)) return 2;
if (sp(y)) return 3;
if (x == '(') {
if (y == ')') return 1;
else {
if (y == ']' || y == '}' || y == '>') return 0;
return 4;
}
} else if (x == '[') {
if (y == ']') return 1;
else {
if (y == ')' || y == '}' || y == '>') return 0;
return 4;
}
} else if (x == '{') {
if (y == '}') return 1;
else {
if (y == ')' || y == ']' || y == '>') return 0;
return 4;
}
} else if (x == '<') {
if (y == '>') return 1;
else {
if (y == ')' || y == ']' || y == '}') return 0;
return 4;
}
}
return 4;
}
signed main() {
freopen("kakko.in", "r", stdin);
freopen("kakko.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--) {
cin >> s;
cnt = 0, ans = 0, sum = 0;
while (!stk.empty()) stk.pop();
for (int i = 0; i <= s.size(); i++) {
if (i == s.size()) {
if (stk.size()) {
cout << "FALSE\n";
break;
}
cout << "TRUE " << ans << " " << sum << "\n";
break;
}
if (stk.empty()) {
if (z(s[i]) == 0) {
cout << "FALSE\n";
break;
}
stk.push(s[i]);
cnt++;
if (cnt == ans) sum++;
if (cnt > ans) {
ans = cnt;
sum = 1;
}
continue;
}
char a = stk.top();
stk.push(s[i]);
if (ck(a, s[i]) == 1) {
stk.pop();
stk.pop();
cnt--;
} else if (ck(a, s[i]) == 0) {
cout << "FALSE\n";
break;
} else if (ck(a, s[i]) == 2) {
continue;
} else if (ck(a, s[i]) == 3) {
continue;
} else {
if (z(s[i]));
cnt++;
if (cnt == ans) sum++;
if (cnt > ans) {
ans = cnt;
sum = 1;
}
}
}
}
return 0;
}