-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxSt.cpp
More file actions
53 lines (51 loc) · 996 Bytes
/
Copy pathmaxSt.cpp
File metadata and controls
53 lines (51 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
vector<int> getMax(vector<string> operations) {
int s= operations.size(),top = -1;
vector<int> stack;
for(int i=0;i<s;i++)
{
stringstream ss(operations[i]);
int x=0;
ss>>x;
if(x==1)
{
long int y=0;
ss>>y;
top = top +1;
stack.push_back(y);
}
else if(x==2){
if(top==-1)
continue;
stack.pop_back();
top = top-1;
}
else if(x==3)
{
cout << *max_element(stack.begin(), stack.end());
}
}
return stack;
}
int main()
{
int n;
cin>>n;
string s;
vector<string> op;
cout<< "enter values\n";
for(int i = 0;i<=n;i++)
{
getline(cin,s);
op.push_back(s);
}
//op.push_back("1 83");
//op.push_back("3");
//op.push_back("2");
//op.push_back("1 76");
getMax(op);
}