八个wonderful answer
2024-07-12 23:11:59
发布于:上海
26阅读
0回复
0点赞
#include <iostream>
#include <stack>
using namespace std;
stack<int> stk,mstk;
int main(){
int n;
int min_num = 0x3f3f3f3f;
cin >> n;
while (n--){
string x;
cin >> x;
if(x == "top"){
if(stk.empty()){
cout << "error" << "\n";
}else{
cout << stk.top() << "\n";
}
}else if(x == "push"){
int x2;
cin >> x2;
stk.push(x2);
if (x2 < min_num){
min_num = x2;
mstk.push(x2);
}else{
mstk.push(mstk.top());
}
}else if(x == "pop"){
if(stk.empty()){
cout << "error" << "\n";
}else{
stk.pop();
mstk.pop();
}
}else{
if(stk.empty()||mstk.empty()){
cout << "error" << "\n";
}else{
cout << min_num << "\n";
}
}
}
return 0;
}
全部评论 2
get_min函数被你吞了
2024-07-12 来自 广东
0一共就这几个操作,不会有别的呀,不是top,push,pop,就是get_min......
2024-07-12 来自 上海
0哦哦没看到
2024-07-12 来自 广东
0
不到错哪了
2024-07-12 来自 上海
0
有帮助,赞一个