18 solutions

  • 1
    @ 2025-3-29 19:07:53

    数组模拟栈 or stack

    #include <bits/stdc++.h>
    #define endl '\n'
    using namespace std;
    typedef pair<int, int> PII;
    using ll = long long;
    using ULL = unsigned long long;
    const int N = 1e7 + 5;
    
    char c;
    stack<char> s;
    char stk[N];
    int tt;
    inline void solve() {
    /* 
       while (cin >> c && c!='@') {
            if (c == '(') {
                s.push(c);
            }
            if (c == ')') {
                if (!s.empty()) {
                    s.pop();
                }else {
                    cout << "NO" << endl;
                    return;
                }
            }
        }
        if (s.empty()) cout << "YES" << endl;
        else cout << "NO" << endl;  
    */
        while (cin >> c && c!='@') {
            if (c == '(') {
                stk[++tt] = c;
            }
            if (c == ')') {
                if (tt) {
                    --tt;
                }else {
                    cout << "NO" << endl;
                    return;
                }
            }
        }
        if (tt) cout << "NO" << endl;
        else cout << "YES" << endl; 
    }
     
    int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        int _ = 1;
        //int _; cin >> _;
        while (_--) solve();
        return 0;
    }
    

    Information

    ID
    289
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    5
    Tags
    # Submissions
    248
    Accepted
    91
    Uploaded By