社区讨论
33tps求调
B3614【模板】栈参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @m0kh2pnu
- 此快照首次捕获于
- 2024/09/02 12:00 2 年前
- 此快照最后确认于
- 2025/11/04 21:51 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int t,n;
stack<unsigned long long> stk;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> t;
for(int i = 1;i <= t;i++){
cin >> n;
for(int j = 1;j <= n;j++){
string s;
cin >> s;
if(s == "push"){
int x;
cin >> x;
stk.push(x);
}
else if(s == "pop"){
if(stk.empty()){
cout << "Empty" << "\n";
}
else{
stk.pop();
}
}
else if(s == "query"){
if(stk.empty()){
cout << "Anguei!" << "\n";
}
else{
cout << stk.top() << "\n";
}
}
else{
cout << stk.size() << "\n";
}
}
while(!stk.empty()){
stk.pop();
}
}
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...