30分求调
查看原帖
30分求调
1015305
lzhAC楼主2024/9/16 10:17

30分求调

#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n;
string str;
stack<long long>s;
signed main(){
	cin>>t;
	while(t--){
		cin>>n;
		while(n--){
			cin>>str;
			if(str=="push"){
				int x;
				cin>>x;
				s.push(x);
			}
			else if(str=="pop"){
				if(s.empty()) puts("Empty");
				else s.pop();
			}
			else if(str=="query"){
				if(s.empty()) puts("Anguei!");
				else cout<<s.top()<<"\n";
			}
			else{
				cout<<s.size()<<"\n";
			}
		}
	}
	return 0;
}
2024/9/16 10:17
加载中...