33分求调
查看原帖
33分求调
1567326
Somakura楼主2024/12/29 23:06
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve(){
	stack<ll> stk;
	ll n; cin >> n;
	for(ll i = 1; i <= n; i++){
		string s1;cin >> s1;
		if(s1 == "push"){
			ll x; cin >> x;
			stk.push(x);
		}
		if(s1 == "pop"){
			if(!stk.empty()) stk.pop();
			else cout << "Empty" << endl;
		}
		if(s1 == "query"){
			if(stk.empty())cout << "Anguei!" << endl;
			else{
				ll put = stk.top();
				cout << put << endl;
			}
		}
		if(s1 == "size"){
			ll sum = 0; sum = stk.size();
			cout << sum << endl;
		}
		
	}

	
}

int main(){
	ll _; cin >> _;
	while(_--){
		solve();
	}
	
	return 0;
}
2024/12/29 23:06
加载中...