比赛 ?板子大赛 评测结果 AAAAA
题目名称 括号匹配 最终得分 100
用户昵称 王潇翊 运行时间 0.680 s
代码语言 C++ 内存使用 5.41 MiB
提交时间 2026-01-17 10:24:42
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
long long n;
int main()
{
    freopen("kakko.in","r",stdin);
    freopen("kakko.out","w",stdout);
    cin >> n;
    for (int i = 1;i <= n;i++)
    {
        stack<char> a;
        string s;
        bool f = 0;
        long long d1 = 0,d = 0,b = 0;
        cin >> s;
        for (int i = 0;i < s.size();i++)
        {
            char c = s[i];
            if (c == '<' || c == '(' || c == '[' || c == '{')
            {
                a.push(c);
            }
            else if (c == '/')
            {
                a.push('1');
            }
            else if (c == '#')
            {
                a.push('2');
                d1++;
            }
            else if (c == '@')
            {
                a.push('4');
                d1 += 3; 
            }
            else if (c == '?')
            {
                a.push('8');
                d1 += 7; 
            }
            else if (c == 92 || c == '*' || c == '&' || c == '!')
            {
                int x;
                bool f1 = 0;
                if (c == 92)
                {
                    x = 1;
                }
                else if (c == '*')
                {
                    x = 2;
                }
                else if (c == '&')
                {
                    x = 4;
                }
                else
                {
                    x = 8;
                }
                while (x != 0)
                {
                    if (a.empty())
                    {
                        f1 = 1;
                        break;
                    }
                    if (a.top() >= '0' && a.top() <= '9')
                    {
                        a.top()--;
                        if (a.top() == '0')
                        {
                            a.pop();
                        }
                        else
                        {
                            d1--;
                        } 
                    }
                    else
                    {
                        a.pop();
                    }
                    x--;
                }
                if (f1)
                {
                    f = 1;
                    break;
                }
            }
            else
            {
                if (a.empty())
                {
                    f = 1;
                    break;
                }
                if (a.top() >= '0' && a.top() <= '9')
                {
                    a.top()--;
                    if (a.top() == '0')
                    {
                        a.pop();
                    }
                    else
                    {
                        d1--;
                    } 
                }
                else
                {
                    if (c == ')' && a.top() != '(')
                    {
                        f = 1;
                        break;
                    }
                    else if (c == ']' && a.top() != '[')
                    {
                        f = 1;
                        break;
                    }
                    else if (c == '}' && a.top() != '{')
                    {
                        f = 1;
                        break;
                    }
                    else if (c == '>' && a.top() != '<')
                    {
                        f = 1;
                        break;
                    }
                    else
                    {
                        a.pop();
                    }
                }
            }
            if (a.size() + d1 > d)
            {
                d = a.size() + d1;
                b = 1;
            }
            else if (a.size() + d1 == d)
            {
                b++;
            }
        }
        if (f || !a.empty())
        {
            cout << "FALSE";
        }
        else
        {
            cout << "TRUE " << d << " " << b;
        }
        cout << endl;
    }
    return 0;
}