33pts求调

B3614 【模板】栈

Ellison2012 @ 2024-08-30 10:14:00

#include <bits/stdc++.h>
using namespace std;
#define int long long
unsigned long long n;
signed main(){
    unsigned long long t;
    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"){
                long long x;
                cin >> x;
                s.push(x);
            }
            if(op == "query"){
                if(!s.empty()){
                    cout << s.top() << endl;
                }else{
                    cout << "Anguei!" << endl;
                }
            }
            if(op == "pop"){
                if(!s.empty()){
                    s.pop();
                }else{
                    cout << "Empty" << endl;
                }
            }
            if(op == "size"){
                cout << s.size() << endl;
            }
        }
    }
    return 0;
}

by happy_zero @ 2024-08-30 10:19:39

@Ellison2012 输入的 x 也要开 unsigned long long


by Yxy7952 @ 2024-08-30 10:36:26

@Ellison2012

#include <bits/stdc++.h>
using namespace std;
#define int long long
unsigned long long n;
signed main(){
    unsigned long long t;
    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 == "query"){
                if(!s.empty()){
                    cout << s.top() << endl;
                }else{
                    cout << "Anguei!" << endl;
                }
            }
            if(op == "pop"){
                if(!s.empty()){
                    s.pop();
                }else{
                    cout << "Empty" << endl;
                }
            }
            if(op == "size"){
                cout << s.size() << endl;
            }
        }
    }
    return 0;
}

by Emplace @ 2024-08-30 10:49:01

@Ellison2012

输入的

x 要开 unsigned long long不然要炸


by Ellison2012 @ 2024-08-31 08:28:55

谢谢,已过


|