30求调
查看原帖
30求调
1190893
quanac_lcx楼主2025/7/29 14:09
#include<iostream>
#include<stack>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
    stack <int> a;
    unsigned long long T;cin>>T;
    while(T--){
        unsigned long long n;
        cin>>n;
        while(n--){
        	string cmd;cin>>cmd;
        if(cmd == "push"){
            unsigned long long x;cin>>x;
            a.push(x);
        }
        else if(cmd == "pop"){
            if(!a.empty()) a.pop();
            else cout<<"Empty"<<endl;
        }
        else if(cmd == "query"){
            if(!a.empty()) cout<<a.top()<<endl;
            else cout<<"Anguei!"<<endl;
        }
        else if(cmd=="size") {
        	if(!a.empty()) cout<<a.size()<<endl;
        	else cout<<0<<endl;
        	
		}
		}
        
    }
    return 0;
}

https://www.luogu.com.cn/record/227566340

2025/7/29 14:09
加载中...