/
khazov
/
module2
Обзор
Документация
Войти
/
khazov
/
module2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
3_task_1_2/task1_2.cpp
50 строк
1 KB
KhazovAV
Первая задача по алгоритмам
04 авг 2026, 13:24
04 авг 2026, 13:24
7e236e8
Код
Авторство
О чём код?
#include <Windows.h> #include <iostream> #include <vector> using namespace std; // ������� ��� �������� ��������� ������ target int countGreater(const std::vector<int>& arr, int target) { int left = 0; int right = static_cast<int>(arr.size()); while (left < right) { int mid = left + (right - left) / 2; if (arr[mid] <= target) { left = mid + 1; // ���� ������� ������ ��� �����, ������ ������� ������� ������ �� mid } else { // ���� ������� ������, �� ����� ���� �������, �� ���� ����� (��������, ���� ��� ������� ������? ���, ��� ����� ������ �������) // �� ����� ����, ���� arr[mid] > target, �� mid - �������� �� �����, ������� ����� ����� �� ����� right = mid; } } // left ������ ��������� �� ������ ������� �������� > target, // ���� ����� ������� �������, ���� ����� ��������� ��� return static_cast<int>(arr.size()) - left; } int main() { int target; vector<int> arr = { 14, 16, 19, 32, 32, 32, 56, 69, 72 }; SetConsoleCP(1251); SetConsoleOutputCP(1251); cout << "������� ����� �������: "; cin >> target; int result = countGreater(arr, target); cout << "���������� ��������� � ������� �������, ��� " << target << ": " << result << endl; return EXIT_SUCCESS; }