Advertisement
Josif_tepe

Untitled

Nov 5th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.     int niza[n];
  9.     for(int i = 0; i < n; i++) {
  10.         cin >> niza[i];
  11.     }
  12.     int x;
  13.     cin >> x;
  14.    
  15.     int od_kade = 0;
  16.     int do_kade = n - 1;
  17.    
  18.     while(od_kade <= do_kade) {
  19.         int sredina = (od_kade + do_kade) / 2;
  20.         if(niza[sredina] == x) {
  21.             cout << "DA" << endl;
  22.             return 0;
  23.         }
  24.         if(x < niza[sredina]) {
  25.             do_kade = sredina - 1;
  26.         }
  27.         else {
  28.             od_kade = sredina + 1;
  29.         }
  30.     }
  31.     cout << "DOOM" << endl;
  32.     return 0;
  33. }
  34. // 73 420
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement