66
查看原帖
66
482610
Mortidesperatslav楼主2023/11/6 19:40
#include<bits/stdc++.h>
using namespace std;
template<class T,int s>
	class cstack{
		public:
			int tp,siz=s;
			T value[s+5];//防溢出操作,自动空出至多40字节,至少5字节空间 
			cstack(){
				this->tp=0;
			}
			bool empty(){
				if(this->tp==0)return true;
				return false;
			}
			int push(T p){
				if(this->tp>=s)return -1;//栈满 
				this->value[tp++]=p;
				return 0;
			}
			int pop(){
				if(tp==0)return -1;
				this->value[this->tp]=__null;
				this->tp--;
				return 0;
			}
			T top(){
				if(tp==0)return  __null;//栈是空的 
				return this->value[this->tp-1];
			}
			T operator[](int x){
				return this->value[x];
			}
			int capacity(){
				return this->siz;
			}
			int size(){
				return this->tp;
			}
			bool operator ==(cstack b){
				if(this->tp!=b.tp)return false;
				for(int i=this->head;i<this->tail;i++)if(this->value[i]!=b[i])return false;
				return true;
			}
	};
cstack<unsigned long long,1000005>s;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<n;i++){
			string ord;
			cin>>ord;
			if(ord=="push"){
				unsigned long long q;
				cin>>q;
				s.push(q);
			}else if(ord=="pop"){
				if(s.empty())cout<<"Empty\n";
				else s.pop();
			}else if(ord=="size")cout<<s.size()<<"\n";
			else if(ord=="query"){
				if(s.empty())cout<<"Anguei!\n";
				else cout<<s.top()<<"\n";
			}
		}
	}
}

无语了。

2023/11/6 19:40
加载中...