B3614 【模板】栈
  • 板块灌水区
  • 楼主a_legend_cat
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/10 10:38
  • 上次更新2024/8/10 11:26:59
查看原帖
B3614 【模板】栈
942515
a_legend_cat楼主2024/8/10 10:38

33分C++代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int times;
	stack<long long>st;
	while(n--) {
		cin >> times;
		for(int i = 0; i < times; i++) {
			string oj;
			cin >> oj;
			if(oj == "push") {
				long long x;
				scanf("%lld",&x);
				st.push(x);
			} else if(oj == "query") {
				if(st.size() == 0) {
					printf("Anguei!\n");
					continue; 
				}
				else printf("%lld\n",st.top());
			} else if(oj == "pop") {
				if(st.size() == 0) {
					printf("Empty\n");
					continue;
				}
				else st.pop();
			} else if(oj == "size") {
				cout << (long long)(st.size()) << endl;
			}
		}
	}
	return 0;
}

有没有大佬告诉我哪里错了......

本蒟蒻委屈地哭......

QAQQAQ

2024/8/10 10:38
加载中...