30分求助
查看原帖
30分求助
561638
Tanhaoyue2011楼主2025/7/24 11:32
#include<iostream>
#include<stack>
#include<string>

using namespace std;


long long n,m,c;
int main(){
	cin >> n;
	for(long long i = 1; i <= n; i++){
		cin >> m;
		stack<int> s;
		string op;
		for(long long j = 1; j <= m; j++){
			cin >> op;
			if(op == "push"){
				cin >> c;
				s.push(c);
			} else if(op == "query"){
				if(s.empty() == true) cout << "Anguei!" << endl;
				else cout << s.top() << endl;
			} else if(op == "pop"){
				if(s.empty() == true) cout << "Empty" << endl;
				else s.pop();
			} else if(op == "size") cout << s.size() << endl;
		}
	}
	return 0;
}
2025/7/24 11:32
加载中...