Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
607 B
2
Indexable
Never
#include <vector>
#include <set>
#include <map>
#include <iostream>
using namespace std;


int main() {
    int n;
    cin >> n;
    
    int niza[n];
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
    }
    
    sort(niza, niza + n);
    int L = 0, R = n - 1;
    int x;
    cin >> x;
    while(L <= R) {
        int middle = (L + R) / 2;
        if(niza[middle] == x) {
            cout << "Da, ovoj broj postoi" << endl;
            break;
        }
        if(x < niza[middle]) {
            R = middle - 1;
        }
        else {
            L = middle + 1;
        }
    }
    return 0;
}
Leave a Comment