Advertisement
Josif_tepe

Untitled

Mar 15th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <map>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. int main()
  10. {
  11.     int n;
  12.     cin >> n;
  13.     int niza[n];
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> niza[i];
  16.     }
  17.     int x;
  18.     cin >> x;
  19.    
  20.     int L = 0;
  21.     int R = n - 1;
  22.     while(L <= R) {
  23.         int middle = (L + R) / 2;
  24.         if(niza[middle] == x) {
  25.             cout << "DA" << endl;
  26.             break;
  27.         }
  28.         if(niza[middle] < x) {
  29.             L = middle + 1;
  30.         }
  31.         else {
  32.             R = middle - 1;
  33.         }
  34.     }
  35.     return 0;
  36. }
  37.  
  38. /*
  39.  
  40.  
  41.  **/
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement