repl.it
C++11

No description

fork
loading
Files
  • main.cpp
main.cpp
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
#include <bits/stdc++.h>
using namespace std;

int most(stack<int> s) {
  int max = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.top() > max) {
      max = s.top();
    }
    s.pop();
  }
}

int main(int argc, const char * argv[]) {
  int n;
  stack<int> s;
  for (int i = 0; i < n; i++) {
    int op;
    cin >> op;
    if (op == 0) {
      int in;
      cin >> in;
      s.push(in);
    }
    else if (op == 1) {
      s.pop();
    }
    else {
      cout << most(s) << endl;
    }
  }
}
Fetching token
?