-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySearch.cpp
More file actions
43 lines (34 loc) · 929 Bytes
/
Copy pathArraySearch.cpp
File metadata and controls
43 lines (34 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <Windows.h>
int count(int* arr, int size, int startingPoint)
{
int left = 0;
int right = size;
while (left < right)
{
int mid = left + (right - left) / 2;
if (arr[mid] > startingPoint)
{
right = mid;
}
else
{
left = mid + 1;
}
}
return size - left;
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int startingPoint;
int arr[] = { 14, 16, 19, 32, 32, 32, 56, 69, 72 };
int size = sizeof(arr) / sizeof(arr[0]);
std::cout << "Введите точку отсчёта: ";
std::cin >> startingPoint;
int point = count(arr, size, startingPoint);
std::cout << "Количество элементов в массиве больших, чем " << startingPoint << ": " << point;
std::cout << std::endl;
return 0;
}