33分求助
查看原帖
33分求助
744029
jr_cct楼主2023/5/1 09:21
#include <iostream>
#include <stack>
using namespace std;
int main(){
	string str;
	int p;
	long long t;
	stack<int>s;
	cin >> t;
	long long tt;
	for(int i = 1;i <= t;i++){
		cin >> tt;
		for(int j = 1;j <= tt;j++){
			cin >> str;
			if(str=="push"){
				cin >> p;
				s.push(p);
			}
			else if(str=="query"){
				if(s.size())cout << s.top()<<endl;
				else cout << "Anguei!"<<endl;
			}
			else if(str=="pop"){
				if(s.size())s.pop();
				else cout << "Empty"<<endl;
			}
			else if(str=="size"){
				cout << s.size()<<endl;
			}
		}
	}
}
2023/5/1 09:21
加载中...