66分求助
查看原帖
66分求助
664234
I_AM_THREE_BODY_MAN楼主2024/5/4 17:27

我最后一个点过不了QWQ

#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m;
string s;
unsigned long long a,t;
class Stack{
	public:
		unsigned long long a[100006];
		void push(unsigned long long value){
			a[t]=value;
			t++;
		}
		void pop(){
			t--;
		}
		unsigned long long top(){
			return a[t-1];
		}
		unsigned long long size(){
			return t;
		}
		bool empty(){
			if(t!=0) return true;
			return false; 
		}
};
int main(){
	Stack st;
	cin>>n;
	while(n--){
		cin>>m;
		for(unsigned long long i=1;i<=m;i++){
			cin>>s;
			if(s=="push"){
				cin>>a;
				st.push(a);
			}
			if(s=="pop"){
				if(st.empty()) st.pop();
				else cout<<"Empty\n";
			}
			if(s=="query"){
				if(st.empty()) cout<<st.top()<<"\n";
				else cout<<"Anguei!\n";
			}
			if(s=="size") cout<<st.size()<<"\n";
		}
	}
	return 0;
}
2024/5/4 17:27
加载中...