AC代码
查看原帖
AC代码
1053898
taoyi20110328楼主2024/3/23 09:01
#include<bits/stdc++.h>
using namespace std;
stack<unsigned long long int>str;
string s,a="push",b="pop",c="query",d="size";
unsigned long long int x;
long long int n,t;
void clean(){
	for(;;){
		if(str.empty()==1){
			return ;
		}
		else{
			str.pop();
		}
	}
}
void push(unsigned long long int x){
	str.push(x);
}
void pop(){
	if(str.empty()==1){
		cout<<"Empty"<<endl;//printf("Empty\n");
	} 
     else{
     	str.pop();
	} 
}
void query(){
	if(str.empty()==1){
		cout<<"Anguei!"<<endl;//printf("Anguei!\n");	
	} 
     else{
     	cout<<str.top()<<endl;//printf("%llu\n",str.top());
	} 
}
void size(){
    cout<<str.size()<<endl;//printf("%llu\n",str.size()); 	
}
int main(){	
	cin>>t;//scanf("%llu",&t);
	while(t--){
	     cin>>n;//scanf("%llu",&n);
		for(int i=1;i<=n;i++){
			cin>>s;
			if(s==a){
			    cin>>x;//scanf("%llu",&x); 
			    push(x);	
			} 
			else if(s==b){
				pop();
			} 
			else if(s==c){
				query(); 
			} 
			else if(s==d){
				size();
			} 
		}
		clean();
	}
	return 0;
} 
2024/3/23 09:01
加载中...