| 比赛 | ?板子大赛 | 评测结果 | AWAEE |
|---|---|---|---|
| 题目名称 | 括号匹配 | 最终得分 | 40 |
| 用户昵称 | rzzakioi | 运行时间 | 0.515 s |
| 代码语言 | C++ | 内存使用 | 12.80 MiB |
| 提交时间 | 2026-01-17 11:14:47 | ||
#include<iostream>
#include<stack>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
string s;
stack<char>st;
int num[2000005];
int 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--){
memset(num,0,sizeof(num));
bool can=1;
cin>>s;
int x=0;
while(!st.empty()){
st.pop();
}
for(int i=0;i<s.size();i++){
if(s[i]=='('||s[i]=='{'||s[i]=='['||s[i]=='<'){
st.push(s[i]);
x++;
num[x]++;
}
else if(s[i]=='/'){
for(int j=1;j<=1;j++){
st.push('1');
x++;
num[x]++;
}
}
else if(s[i]=='#'){
for(int j=1;j<=2;j++){
st.push('1');
x++;
num[x]++;
}
}
else if(s[i]=='@'){
for(int j=1;j<=4;j++){
st.push('1');
x++;
num[x]++;
}
}
else if(s[i]=='?'){
for(int j=1;j<=8;j++){
st.push('1');
x++;
num[x]++;
}
}
else{
if(s[i]==')'){
if(!st.empty()&&(st.top()=='('||st.top()=='1')){
st.pop();
x--;
}
else can=0;
}
else if(s[i]==']'){
if(!st.empty()&&(st.top()=='['||st.top()=='1')){
st.pop();
x--;
}
else can=0;
}
else if(s[i]=='}'){
if(!st.empty()&&(st.top()=='{'||st.top()=='1')){
st.pop();
x--;
}
else can=0;
}
else if(s[i]=='>'){
if(!st.empty()&&(st.top()=='<'||st.top()=='1')){
st.pop();
x--;
}
else can=0;
}
else if(s[i]=='\\'){
for(int j=1;j<=1;j++){
if(!st.empty()){
st.pop();
x--;
}
else can=0;
}
}
else if(s[i]=='*'){
for(int j=1;j<=2;j++){
if(!st.empty()){
st.pop();
x--;
}
else can=0;
}
}
else if(s[i]=='&'){
for(int j=1;j<=4;j++){
if(!st.empty()){
st.pop();
x--;
}
else can=0;
}
}
else if(s[i]=='!'){
for(int j=1;j<=8;j++){
if(!st.empty()){
st.pop();
x--;
}
else can=0;
}
}
}
}
if(can&&st.empty()){
cout<<"TRUE ";
for(int i=s.size();i>=0;i--){
if(num[i]){
cout<<i<<' '<<num[i];
break;
}
}
cout<<'\n';
}
else{
cout<<"FALSE\n";
}
}
return 0;
}