0分求调
查看原帖
0分求调
1390480
zengyanbin楼主2024/9/21 22:35

有没有大神找出错哪了!

#include<iostream>
#include<stack>
using namespace std;

stack<int> q;

int main(){
	unsigned long long t, n, x;
	string h;
	cin>>t;
	for(unsigned long long i1=1;i1<=t;i1++){
		cin>>n;
		for(unsigned long long i=1;i<=n;i++){
			cin>>h;
			if(h=="push"){
				cin>>x;
				q.push(x);
			}else if(h=="pop"){
				if(q.empty()){
					cout<<"Empty"<<endl;
				}else{
					q.pop();
				}
			}else if(h=="query"){
				if(q.empty()){
					cout<<"Empty"<<endl;
				}else{
					q.top();
				}
			}else if(h=="size"){
				cout<<q.size()<<endl;
			}
		}
	}
	return 0;
}
2024/9/21 22:35
加载中...