Advertisement
Josif_tepe

Untitled

Mar 31st, 2024
795
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 <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.    
  11.     int x;
  12.     cin >> x;
  13.    
  14.     int niza[n];
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> niza[i];
  17.     }
  18.    
  19.     sort(niza, niza + n);
  20.    
  21.     int L = 0, R = n - 1;
  22.     while(L <= R) {
  23.         int middle = (L + R) / 2;
  24.         if(niza[middle] == x) {
  25.             cout << "Ovoj broj postoi vo nizata" << endl;
  26.             return 0;
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement