Advertisement
Spocoman

01. Basic Stack Operations

Jan 11th, 2024
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int N, S, X, n, minNum = 2147483647;
  8.     cin >> N >> S >> X;
  9.  
  10.     stack<int> numbers;
  11.  
  12.     for (int i = 0; i < N; i++) {
  13.         cin >> n;
  14.         numbers.push(n);
  15.     }
  16.  
  17.     for (int i = 0; i < S; i++) {
  18.         numbers.pop();
  19.         if (numbers.empty()) {
  20.             cout << '0' << endl;
  21.             return 0;
  22.         }
  23.     }
  24.  
  25.     while (!numbers.empty()) {
  26.         if (numbers.top() == X) {
  27.             cout << "true" << endl;
  28.             return 0;
  29.         }
  30.         else if (numbers.top() < minNum) {
  31.             minNum = numbers.top();
  32.         }
  33.         numbers.pop();
  34.     }
  35.  
  36.     cout << minNum << endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement