社区讨论

全红

B3614【模板】栈参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@m6vos2j4
此快照首次捕获于
2025/02/08 12:19
去年
此快照最后确认于
2025/11/04 09:45
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
stack<int>a;
string order;
int t;
int main() {
	scanf("%d",&t);
	while(t--){
		cin>>order;
		if(order == "push"){
			int x;
			scanf("%d\n",&x);
			a.push(x);
		}
		else if(order == "pop"){
			if(a.empty())printf("Empty\n");
			else a.pop();
		}
		else if(order == "query"){
			if(a.size() == 0)printf("Anguei!\n");
			else printf("%d\n",a.top());
		}
		else printf("%d",a.size());
		int x = a.size();
		while(x--)a.pop();
	}
	return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...