Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int* createMas(int n)
- {
- int* mas = new int[n];
- for (int i = 0; i < n; ++i) cin >> mas[i];
- return mas;
- }
- int main()
- {
- int n;
- cin >> n;
- int* mas = createMas(n);
- int l = 0;
- int r = n - 1;
- int value;
- cin >> value;
- while (l < r)
- {
- int mid = (l + r) / 2;
- if (value < mas[mid]) r = mid + 1;
- else if (value > mas[mid]) l = mid;
- else if (value == mas[mid])
- {
- cout << mid << endl;
- break;
- }
- }
- delete[] mas;
- return 0;
- }
Add Comment
Please, Sign In to add comment