33
查看原帖
33
784704
kevin4楼主2023/9/26 21:08
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct Stack {
	int p,a[100001];
	Stack() : p(0) {}
	void push(int x) {
		a[p++] = x;
	}
	bool empty() {
		return p==0;
	}
	void pop() {
		if(p!=0)--p;
	}
	int top() {
		return a[p - 1];
	}
	int size() {
		return p;
	}
} s;
string st;
ll n,t,a;
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--) {
		cin>>n;
		while(!s.empty())s.pop();
		while(n--) {
			cin>>st;
//			cout<<st<<endl;
			if(st=="query") {
				if(s.empty())cout<<"Anguei!"<<endl;
				else cout<<s.top()<<endl;
//				cout<<"01"<<endl;
			}
			if(st=="pop") {
				if(s.empty())cout<<"Empty"<<endl;
				else s.pop();
//				cout<<"02"<<endl;
			}
			if(st=="size") {
				cout<<s.size()<<endl;
//				cout<<"03"<<endl;
			}
			if(st=="push") {
				cin>>a;
				s.push(a);
//				cout<<"04"<<endl;
			}
		}
	}
	return 0;
}

2023/9/26 21:08
加载中...