Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main() {
- int n, command, number;
- cin >> n;
- stack<int> numbers, s;
- for (int i = 0; i < n; i++) {
- cin >> command;
- if (command == 1) {
- cin >> number;
- numbers.push(number);
- }
- else if (numbers.size() > 0) {
- if (command == 2) {
- numbers.pop();
- }
- else {
- int max = -2147483646, min = 2147483647;
- s = numbers;
- while (s.size() != 0) {
- if (s.top() > max) {
- max = s.top();
- }
- if (s.top() < min) {
- min = s.top();
- }
- s.pop();
- }
- cout << (command == 3 ? max : min) << endl;
- }
- }
- }
- if (numbers.size() > 0) {
- while (numbers.size() != 1) {
- cout << numbers.top() << ", ";
- numbers.pop();
- }
- cout << numbers.top() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement