1 solutions

  • 1
    @ 2023-10-14 23:55:12

    水题

    这道题只是坑在数据范围,很多人因此第一遍没A。

    0x2640 \leq x \leq 2^{64}

    没错,不开long long见祖宗,但开了long long也见祖宗。。。

    得开unsigned long long哦吼。

    AC CODE

    #include <iostream>
    #include <string>
    #include <stack>
    
    using namespace std;
    
    int t, n;
    
    int main () {
        cin >> t;
        while (t--) {
        stack <unsigned long long> s;
            cin >> n;
            for (int i = 1; i <= n; i++) {
                string op;
                cin >> op;
                if (op == "push") {
                    unsigned long long x;
                    cin >> x;
                    s.push(x);
                }
                if (op == "pop") {
                    if (s.size() == 0) {
                        cout << "Empty\n";
                    }
                    else {
                        s.pop();
                    }
                }
                if (op == "query") {
                    if (s.size() == 0) {
                        cout << "Anguei!\n";
                    }
                    else {
                        cout << s.top() << "\n";
                    }
                }
                if (op == "size") {
                    cout << s.size() << "\n";
                }
            }
        }
        return 0;
    }
    
    • 1

    Information

    ID
    5604
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    2
    Tags
    # Submissions
    5
    Accepted
    2
    Uploaded By