社区讨论
WA#1 求调
B3614【模板】栈参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lxon6zef
- 此快照首次捕获于
- 2024/06/21 20:03 2 年前
- 此快照最后确认于
- 2024/06/21 22:35 2 年前
CPP
#include <iostream>
#include <stack>
using namespace std;
stack <unsigned long long> m;
int main() {
unsigned long long t, n;
cin >> t >> n;
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= n; j++) {
string s;
unsigned long long x;
cin >> s;
if (s == "push") {
cin >> x;
m.push(x);
}
else if (s == "pop" && m.empty()) cout << "Empty" << endl;
else if (s == "pop") m.pop();
else if (s == "query" && m.empty()) cout << "Anguei!" << endl;
else if (s == "query") cout << m.top() << endl;
else if (s == "size") cout << m.size() << endl;
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...