题目大意
模拟栈(1操作入栈,2操作出栈),栈空输出“Impossible!”
思路
直接模拟,即可。
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int main() {
int n, c, m;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c;
if (c == 2)
s.pop();
else {
cin >> m;
s.push(m);
}
}
if (s.empty())
cout << "impossible!";
else
cout << s.top();
}