社区讨论
样例没过,9个WA1个TLE
B3614【模板】栈参与者 6已保存回复 20
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 19 条
- 当前快照
- 1 份
- 快照标识符
- @mdi6gack
- 此快照首次捕获于
- 2025/07/25 10:03 7 个月前
- 此快照最后确认于
- 2025/07/25 14:53 7 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
stack <int> st;
int t, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
while (n--) {
string s;
cin >> s;
if (s == "Push") {
int x;
cin >> x;
st.push(x);
}
else if (s == "pop") {
if (!st.empty()) st.pop();
else cout << "Empty" << endl;
}
else if (s == "query") {
if (!st.empty()) cout << st.top() << endl;
else cout << "Anguei!";
}
else if (s == "size") {
cout << st.size();
}
}
}
while (!st.empty()) {
cout <<st.top() << " ";
st.pop();
}
return 0;
}
回复
共 20 条回复,欢迎继续交流。
正在加载回复...