题目1522:包含min函数的栈
来源:互联网 发布:河南省南乐县网络电视 编辑:程序博客网 时间:2024/06/04 18:44
#include <iostream>#include <cstdio>#include <stack> using namespace std; int main(){ stack<int> st,st_min; int n,x; char s[2]; while(scanf("%d",&n)!=EOF) { for(int i=0; i<n; i++) { scanf("%s",&s); if(s[0]=='s') { scanf("%d",&x); st.push(x); if(!st_min.empty()) { int t=st_min.top(); if(x<t) { st_min.push(x); } } else { st_min.push(x); } printf("%d\n",st_min.top()); } else { if(!st.empty()) { int t=st.top(); st.pop(); if(t==st_min.top()) { st_min.pop(); } } if(!st_min.empty()) { printf("%d\n",st_min.top()); } else { printf("NULL\n"); } } } } return 0;} /************************************************************** Problem: 1522 User: jasonhaven Language: C++ Result: Accepted Time:20 ms Memory:1524 kb****************************************************************/
0 0
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目1522:包含min函数的栈
- 题目21:包含min函数的栈
- 算法题目---包含min函数的栈
- 题目1522:包含min函数的栈-九度
- 【九度】题目1522:包含min函数的栈
- 九度oj 题目1522:包含min函数的栈
- 九度 题目1522:包含min函数的栈
- 九度_题目1522:包含min函数的栈
- 九度OJ-题目1522:包含min函数的栈
- 剑指Offer题目1522:包含min函数的栈
- 【LeetCode】Min Stack && 【九度】题目1522:包含min函数的栈
- 控制台输出console.log()的用法
- Java功底之static、final、this、super
- 常用操作技巧总结
- Ubuntu 16.04 虚拟机安装记录
- [JZOJ5061]最长路径
- 题目1522:包含min函数的栈
- 混合数组
- (懒人必备)Android开源数据库LitePal
- 坏道填补与去条带处理
- android自动化测试Monkeyrunner源码分析之二
- 智能指针总结
- Spring Boot学习(一)
- ecshop打开手机端QQ对话窗口
- POJ 1050 To the Max【DP】