33???
查看原帖
33???
1155902
w_w_J楼主2024/11/20 22:56
#include <iostream>
#include <stack>
#include <string> 
using namespace std;
int main(){
	int T;
	cin>>T;
	for(int j=0;j<T;j++){
		int n;
		cin>>n;//操作次数
		stack<int> q;
		for(int i=0;i<n;i++){
			string s="0";
			cin>>s;
			if(s=="push") {
				int k;
				cin>>k;
				q.push(k); 
			}
			if(s=="query"){
				if(q.empty()) cout<<"Anguei!"<<endl;
				else cout<<q.top()<<endl;
			}
			if(s=="pop"){
				if(q.empty()) cout<<"Empty"<<endl;
				else q.pop();
			}
			if(s=="size"){
				cout<<q.size()<<endl;
			}
		} 
	}
	return 0;
}

}

2024/11/20 22:56
加载中...