比赛 ?板子大赛 评测结果 WWWEE
题目名称 括号匹配 最终得分 0
用户昵称 你好 运行时间 0.560 s
代码语言 C++ 内存使用 5.83 MiB
提交时间 2026-01-17 10:52:23
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<string>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
int n;
bool l(char a){
    return a=='('||a=='['||a=='{'||a=='<';
}
bool check(char a,char b){
    return (a=='('&&b==')')||(a=='['&&b==']')||(a=='{'&&b=='}')||(a=='<'&&b=='>');
}
int main(){
    freopen("kakko.in","r",stdin);
    freopen("kakko.out","w",stdout);
    cin>>n;
    while(n--){
        stack<char>s1,s2;
        vector<int>a;
        string s;
        cin>>s;
        if(!l(s[0])){
            cout<<"FALSE\n";
            continue;
        }
        int depth=0;
        for(auto i:s){
            if(l(i))s1.push(i),depth++;
            else if(check(s1.top(),i)){
                a.push_back(depth);
                depth=0;
                s1.pop();
                s2.push(i);
            }
        }
        sort(a.begin(),a.end());
        int tot=0;
        for(auto i:a)tot+=(i==a[a.size()-1]); 
        if(s1.size()==0)
            cout<<"TRUE "<<a[a.size()-1]<<' '<<tot<<endl;
        else cout<<"FALSE\n";
    }
    return 0;
}