Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int binarnie(int *arr, int n, int x){
- int min = 0;
- int max = n - 1;
- while (min <= max)
- {
- int m = (min + max)/ 2;
- if (arr[m] == x)
- return m;
- if(arr[m] < x)
- min = m + 1;
- else max = m - 1;
- }
- return -1;
- }
- int main(int argc, const char * argv[]){
- int n;
- cin >> n;
- int present[n];
- for (int i = 0; i < n; i++) {
- cin >> present[i];
- }
- int d;
- cin >> d;
- for (int j = 0; j < d; j++) {
- int asked;
- cin >> asked;
- int place = binarnie(obecni, n, asked);
- if (place == -1){
- cout << "NIEOBECNY\n" << endl;
- }
- else{
- cout << place + 1 << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement