33分求调
查看原帖
33分求调
741937
harryzhou楼主2024/8/13 15:17
#include <bits/stdc++.h>
using namespace std;

int main(){
    unsigned long long T;
    cin >> T;
    while(T--){
        stack <unsigned long long> s;
        unsigned long long n;
        cin >> n;
        for(unsigned long long i = 1; i <= n; i++){
            string s1;
            cin >> s1;
            if(s1 == "push"){
                unsigned long long x;
                scanf("%lld", &x);
                s.push(x);
            }
            else if(s1 == "pop"){
                if(s.empty()){
                    cout << "Empty\n";

                }
                else s.pop();
            }
            else if(s1 == "query"){
                if(s.empty()){
                    cout << "Anguei!\n";
                }
                else cout << s.top() << endl;
            }
            else if(s1 == "size"){
                cout << s.size() << endl;
            }

        }
        while(!s.empty()){
			s.pop();
		}
    }
    return 0;
}
2024/8/13 15:17
加载中...