Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- 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 x;
- cin >> x;
- int L = 0, R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(x == niza[middle]) {
- cout << "Brojot " << x << " postoi vo nizata" << endl;
- break;
- }
- if(x < niza[middle]) {
- R = middle - 1;
- }
- else {
- L = middle + 1;
- }
- }
- return 0;
- }
- // 972
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement