33分求调(玄关)
查看原帖
33分求调(玄关)
1432246
_qumingnan_楼主2024/10/20 17:26
#include<bits/stdc++.h>
using namespace std;
string s;
int t,n;
long long x,a[1000005],tot,top;
int main(){
	//freopen("栈.txt","w",stdout);
	cin>>t;
	while(t--){
		top=1;
		tot=0;
		cin>>n;
		while(n--){
			cin>>s;
			if(s=="push"){
				cin>>x;
				++tot;
				a[tot]=x;
			}
			else if(s=="pop"){
				if(tot-top+1<=0)cout<<"Empty\n";
				else top++;
			}
			else if(s=="query"){
				if(tot-top+1<=0)cout<<"Anguei!\n";
				else cout<<a[top]<<endl;
			}
			else if(s=="size")cout<<tot-top+1<<endl;
			/*for(int i=tot;i<=top;i++){
				cout<<a[i]<<' '
			}
			cout<<tot<<' '<<top<<endl;*/
		}
	}
	return 0;
}
2024/10/20 17:26
加载中...