Maximum Element——stack
来源:互联网 发布:软件测试周末班 编辑:程序博客网 时间:2024/06/06 14:20
Maximum Element
You have an empty sequence, and you will be given queries. Each query is one of these three types:
1 x -Push the element x into the stack.
2 -Delete the element present at the top of the stack.
3 -Print the maximum element in the stack.
Input Format
The first line of input contains an integer, . The next lines each contain an above mentioned query.(It is guaranteed that each query is valid.)
Constraints
Output Format
For each type query, print the maximum element in the stack on a new line.
Sample Input
10
1 97
2
1 20
2
1 26
1 20
2
3
1 91
3
Sample Output
26
91
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main()
{
stack<int>v;
int n;
cin>>n;
while(n--)
{
int ch;
cin>>ch;
if(ch==1)
{
int x;
cin>>x;
v.push(max(x,v.size()>0?v.top():x));
cout<<v.top()<<endl;
cout<<max(x,v.size()>0?v.top():x)<<endl;
//stack容器的栈顶元素的读取函数为top函数 将取出最后入栈的元素
//如果没有元素 输入元素
//如果有元素 比较输入元素与原来元素的大小 存大的
}
else if(ch==2)
{
v.pop();
}
else if(ch==3)
{
cout<<v.top()<<endl;
}
}
return 0;
}
- Maximum Element——stack
- CF886E Maximum Element
- Maximum call stack size exceeded
- Maximum call stack size exeeded
- Maximum call stack size exceeded
- LeetCode—Majority Element
- Maximum Subarray & Climbing Stairs & Remove Element
- 169 Majority Element & 53 Maximum Subarray
- LeetCode Stack Problem || Next Greater Element
- Stack——栈
- 数据结构——Stack
- 未知异常: Maximum call stack size exceeded
- Maximum call stack size exceeded异常原因
- Uncaught RangeError: Maximum call stack size exceeded
- Uncaught RangeError: Maximum call stack size exceeded
- Uncaught RangeError: Maximum call stack size exceeded
- .trigger Maximum call stack size exceeded
- Js: Maximum call stack size exceeded
- calibrate kinnect v1 on ubuntu
- 定义一个宏,实现对数据a的第n位置位、清零、取反
- Maps-STL
- Java中List Set Map 是否有序等总结(转载)
- JAVA小结
- Maximum Element——stack
- [BigData] HBase 集成 Phoenix SQL 查询引擎
- Hbase的架构和实现原理
- day1:MVC设计模式
- 分布式事务原理与实践
- Spring Cloud云服务
- redis常用命令
- windows github教程
- Ubuntu16.04 自己创造环境变量