33分求助
查看原帖
33分求助
1079323
Luo_Yang123123楼主2024/5/18 20:53
#include<bits/stdc++.h>
using namespace std;
int main(){
	stack<unsigned long long int>z;
	
	unsigned long long int t;
	scanf("%lld",&t);
	for(unsigned long long int i=0;i<t;i++){
		unsigned long long int n;
		scanf("%lld",&n);
		for(unsigned long long int j=0;j<n;j++){
			string s;
			cin>>s;
			if(s=="push"){
				unsigned long long int x;
				scanf("%lld",&x);
				z.push(x);
			}else if(s=="pop"){
				if(z.empty()){
					cout<<"Empty\n";
				}else{
					z.pop();
				}
			}else if(s=="query"){
				if(z.empty()){
					cout<<"Anguei!\n";
				}else{
					cout<<z.top()<<endl;
				}
			}else if(s=="size"){
				cout<<z.size()<<endl;
			}
		}
	}
	return 0;
	
}
2024/5/18 20:53
加载中...