33tps求调

B3614 【模板】栈

chenjunyi12 @ 2024-09-02 11:59:39

#include<bits/stdc++.h>
using namespace std;
int t,n;
stack<unsigned long long> stk; 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    for(int i = 1;i <= t;i++){
        cin >> n;
        for(int j = 1;j <= n;j++){
            string s;
            cin >> s;
            if(s == "push"){
                int x;
                cin >> x;
                stk.push(x);
            }
            else if(s == "pop"){
                if(stk.empty()){
                    cout << "Empty" << "\n";
                }
                else{
                    stk.pop();
                }
            }
            else if(s == "query"){
                if(stk.empty()){
                    cout << "Anguei!" << "\n";
                }
                else{
                    cout << stk.top() << "\n";
                }
            }
            else{
                cout << stk.size() << "\n";
            }
        }
        while(!stk.empty()){
            stk.pop();
        }
    }
    return 0;
}

by Yxy7952 @ 2024-09-02 12:32:09

@chenjunyi12

#include<bits/stdc++.h>
using namespace std;
int t,n;
stack<unsigned long long> stk; 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    for(int i = 1;i <= t;i++){
        cin >> n;
        for(int j = 1;j <= n;j++){
            string s;
            cin >> s;
            if(s == "push"){
                unsigned long long x;//该unsigned long long
                cin >> x;
                stk.push(x);
            }
            else if(s == "pop"){
                if(stk.empty()){
                    cout << "Empty" << "\n";
                }
                else{
                    stk.pop();
                }
            }
            else if(s == "query"){
                if(stk.empty()){
                    cout << "Anguei!" << "\n";
                }
                else{
                    cout << stk.top() << "\n";
                }
            }
            else{
                cout << stk.size() << "\n";
            }
        }
        while(!stk.empty()){
            stk.pop();
        }
    }
    return 0;
}

by chenjunyi12 @ 2024-09-02 13:04:28

谢谢大佬!!!@yixingyou


by machenchang @ 2024-10-04 15:47:57

@chenjunyi12 你才大佬


|