1 条题解

  • 0
    @ 2022-11-2 15:53:50
    #include <bits/stdc++.h>
    using namespace std;
    string str;
    stack<char> sta;
    int main()
    {
        cin >> str;
        for (int i = 0; i < str.length(); i++)
        {
            if (str[i] == '(' || str[i] == '[')
                sta.push(str[i]);
            else if (str[i] == ')' || str[i] == ']')
            {
                if (sta.empty() ||
                    str[i] == ')' && sta.top() == '[' ||
                    str[i] == ']' && sta.top() == '(')
                {
                    cout << "Wrong\n";
                    return 0;
                }
                else
                    sta.pop();
            }
        }
        if (sta.empty())
            cout << "OK\n";
        else
            cout << "Wrong\n";
        return 0;
    }
    
    • 1

    信息

    ID
    573
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    (无)
    递交数
    133
    已通过
    41
    上传者