Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int binarnie(int *arr, int n, int x){
  6.  
  7.   int min = 0;
  8.   int max = n - 1;
  9.  
  10.   while (min <= max)
  11.   {
  12.     int m = (min + max)/ 2;
  13.  
  14.     if (arr[m] == x)
  15.       return m;
  16.  
  17.     if(arr[m] < x)
  18.       min = m + 1;
  19.  
  20.     else max = m - 1;
  21.   }
  22.  
  23.   return -1;
  24. }
  25.  
  26. int main(int argc, const char * argv[]){
  27.  
  28.   int n;
  29.   cin >> n;
  30.  
  31.   int present[n];
  32.  
  33.   for (int i = 0; i < n; i++) {
  34.     cin >> present[i];
  35.   }
  36.  
  37.   int d;
  38.   cin >> d;
  39.  
  40.   for (int j = 0; j < d; j++) {
  41.     int asked;
  42.     cin >> asked;
  43.  
  44.     int place = binarnie(obecni, n, asked);
  45.  
  46.     if (place == -1){
  47.       cout << "NIEOBECNY\n" << endl;
  48.     }
  49.  
  50.     else{
  51.       cout << place + 1 << endl;
  52.     }
  53. }
  54.  
  55.   return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement