社区讨论
49分求助
P1165日志分析参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjq8gsm
- 此快照首次捕获于
- 2025/11/04 06:43 4 个月前
- 此快照最后确认于
- 2025/11/04 06:43 4 个月前
后三个点T,求助(不道怎么优化)
CPP#include<bits/stdc++.h>
using namespace std;
int n,a,x;
stack<int>s;
stack<int>ts;
void fz(){
while(!s.empty()){
ts.push(s.top());
s.pop();
}
}
void maxnn(){
int maxn=-1;
while(!ts.empty()){
maxn=max(maxn,ts.top());
s.push(ts.top());
ts.pop();
}
cout<<maxn<<endl;
maxn=-1;
}
int main (){
cin>>n;
while(n--){
cin>>a;
if(a==0){
cin>>x;
s.push(x);
}else if(a==1){
if(!s.empty()){
s.pop();
}
}else if(a==2){
if(s.empty()){
cout<<0;
}else{
fz();
maxnn();
}
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...