33分求调
查看原帖
33分求调
1350521
SimonLan楼主2024/8/29 12:29
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
        stack<long long int> s;
		cin>>m;
		for(int j=1;j<=m;j++){
			string h;
			cin>>h;
			if(h=="push"){
				unsigned long long x;
				cin>>x;
				s.push(x);
			}
			if(h=="query"){
				if(s.empty()){
				   cout<<"Anguei!\n";
				}
				else cout<<s.top()<<"\n";
			}
			if(h=="size"){
				cout<<s.size()<<"\n";
			}
			if(h=="pop"){
				if(s.empty()){
					cout<<"Empty\n";
				}
				else s.pop(); 
			}
		}
	}
}

2024/8/29 12:29
加载中...