Author: lllyouo
Date: 20250818
tag: 栈
link: https://www.luogu.com.cn/problem/P1165问题描述
分析
略
参考代码
cpp
#include <bits/stdc++.h>
using namespace std;
int st[200010], top = -1;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N; cin >> N;
st[++top] = 0;
while (N--) {
int op, ans = 0; cin >> op;
if (op == 0) {
int x; cin >> x;
st[++top] = max(st[top], x);
} else if (op == 1) {
if (top >= 0) top--;
} else if (op == 2) {
cout << st[top] << endl;
}
}
return 0;
}