Advertisement
STANAANDREY

bac 4/19/2022 3

Apr 19th, 2022 (edited)
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5. ifstream fin("bac.in");
  6.  
  7. int main() {
  8.     int a, b, c, r = 0, minDif = 1e9;
  9.     fin >> a >> b;
  10.     while (fin >> c) {
  11.         if (b > a && b > c && minDif >= abs(a - c) && r < b) {
  12.             minDif = abs(a - c);
  13.             r = b;
  14.         }
  15.         a = b, b = c;
  16.     }
  17.  
  18.     if (!r) {
  19.         cout << "nu exista" << endl;
  20.     } else {
  21.         cout << r << endl;
  22.     }
  23.     return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement