蒟蒻求助
  • 板块学术版
  • 楼主Lost_Ycy
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/14 11:48
  • 上次更新2023/11/3 09:56:38
查看原帖
蒟蒻求助
748906
Lost_Ycy楼主2023/7/14 11:48

本蒟蒻看到这一题(B3614)之后写的代码如下↓

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

int T,n;
string s;
int main(){
cin>>T;
for(int i=0;i<T;i++){
	cin>>n;
	for(int j=0;j<n;j++){
		stack <int> stk;
		cin>>s;
		if(s=="push"){
			int tmp;
			cin>>tmp;
			stk.push(tmp);
		}
		else if(s=="query"){
			if(stk.empty()) cout<<"Anguei!"<<endl;
			else cout<<stk.top()<<endl;
		}
		else if(s=="pop"){
			if(stk.empty()) cout<<"Empty"<<endl;
			else stk.pop();
		}
		else{
			cout<<stk.size()<<endl;
		}
	}
}
return 0;
}

结果发现push()函数根本用不了!

有神犇可以帮帮忙嘛

2023/7/14 11:48
加载中...