求调

B3614 【模板】栈

molakeser @ 2024-09-27 19:57:27

#include<bits/stdc++.h>

using namespace std;
#define int long long
const int N = 1e6 + 5;

int t, n, x;
string s;
stack<int>p;
signed main() {
    cin >> t;
    while(t--) {
        cin >> n;

        while(n--) {
            cin >> s;
            if(s == "push") {
                cin >> x;
                p.push(x);
            }
            if(s == "pop") {
                if(p.empty())
                    cout << "Empty" << endl;
                else
                    p.pop();
            }
            if(s=="query") {
                if(p.empty())
                    cout << "Anguei!" << endl;
                else
                    cout << p.top()<< endl;
            }
            if(s =="size")
                cout << p.size() << endl;
        }
        while(!p.empty())
            p.pop();
    }
    return 0;
}

by suxiaozhou @ 2024-09-27 20:07:04

#define int long long

#define int unsigned long long


by suxiaozhou @ 2024-09-27 20:11:06

题目保证 0≤x< 2^{64}

使用long long

仅能表示-2^{63} 2^{63}-1 的范围

所以要使用 unsigned long long


by molakeser @ 2024-09-27 20:19:04

谢谢大佬@suxiaozhou


|