一AC二WA,求助
查看原帖
一AC二WA,求助
1165197
Eastern_Leaf楼主2024/7/16 10:16
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long Stack_[1000000]={0},tp = 1;
void push(int x){
	Stack_[tp] =x;
	tp = tp+1; 
}
void pop(){
	if(tp>1){
		tp = tp - 1;
	}else if(tp == 1){
		cout<<"Empty"<<endl;
	}
}
void query(){
	if(tp==1){
		cout<< "Anguei!"<<endl;
	}else{
		cout<< Stack_[tp-1]<<endl;
	}	
}
int size(){
	return tp-1;
}
signed main(){
	int T;
	cin>>T;
	int n,x;
	string op;
	for(int i = 1;i<=T;i++){
		tp = 1;
		cin>>n;
		for(int i = 1;i<=n;i++){
			cin>>op;
			if(op == "push"){
				cin>>x;
				push(x);
			}
			if(op == "pop"){
				pop();
			}
			if(op == "query"){
				query();
			}
			if(op == "size"){
				cout<<size()<<endl;
			}
		}
		memset(Stack_,0,sizeof(int)*1000000);
	}
}
2024/7/16 10:16
加载中...