33tps求调
查看原帖
33tps求调
1023501
chenjunyi12楼主2024/9/2 11:59
#include<bits/stdc++.h>
using namespace std;
int t,n;
stack<unsigned long long> stk; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> t;
	for(int i = 1;i <= t;i++){
		cin >> n;
		for(int j = 1;j <= n;j++){
			string s;
			cin >> s;
			if(s == "push"){
				int x;
				cin >> x;
				stk.push(x);
			}
			else if(s == "pop"){
				if(stk.empty()){
					cout << "Empty" << "\n";
				}
				else{
					stk.pop();
				}
			}
			else if(s == "query"){
				if(stk.empty()){
					cout << "Anguei!" << "\n";
				}
				else{
					cout << stk.top() << "\n";
				}
			}
			else{
				cout << stk.size() << "\n";
			}
		}
		while(!stk.empty()){
			stk.pop();
		}
	}
	return 0;
}
2024/9/2 11:59
加载中...