66分求助
查看原帖
66分求助
545341
qianjingzhen楼主2023/8/24 20:16
#include<bits/stdc++.h>
typedef unsigned long long int ll;
typedef double db;
using namespace std;
ll T,n,x;
stack <ll> q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	std::cin>>T;
	while(T--){
		std::cin>>n;
		string s;
		for(ll i=1;i<=n;i++){
			std::cin>>s;
			if(s=="push"){
				std::cin>>x;
				q.push(x);
			}else{
				if(s=="query"){
					if(q.size()!=0){
						cout<<q.top()<<"\n";
					}else{
						cout<<"Anguei!\n";
					}
				}else{
					if(s=="pop"){
						if(q.size()!=0){
							q.pop();
						}else{
							cout<<"Empty\n";
						}
					}else{
						cout<<q.size()<<"\n";
					}
				}
			}
		}
	}
	return 0;
}
2023/8/24 20:16
加载中...