j33vansh

Answer 5 Looping CPP

Jun 26th, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define FIO                           \
  4.     ios_base::sync_with_stdio(false); \
  5.     cin.tie(NULL);                    \
  6.     cout.tie(NULL);
  7.  
  8. int main()
  9. {
  10.     FIO;
  11.     int n;
  12.     cin >> n;
  13.     int max = INT_MIN, secondMax = INT_MIN;
  14.  
  15.     int num;
  16.     int count = 1;
  17.     while (count <= n)
  18.     {
  19.         cin >> num;
  20.         if (num > max)
  21.         {
  22.             secondMax = max;  
  23.             max = num;        
  24.         }
  25.         else if (num > secondMax && num != max)    
  26.         {
  27.             secondMax = num;
  28.         }
  29.         count++;
  30.     }
  31.     cout << secondMax << endl;
  32. }
Add Comment
Please, Sign In to add comment