Advertisement
Misha_

Код

Dec 14th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <clocale>
  4. using namespace std;
  5.  
  6. int main() {
  7.     setlocale(LC_ALL, "");
  8.     const int SIZE_A = 5, SIZE_B = 3;
  9.  
  10.     int haystack[SIZE_A] = {1, 3, 4, 5, 9};
  11.     int needles[SIZE_B] = {1, 2, 3};
  12.  
  13.     // haystack - массив, в котором будет происходить поиск
  14.     // needles - массив чисел, которые будет искать функция в массиве haystack
  15.  
  16.     for (int i = 0; i < SIZE_B; ++i) {
  17.         cout << "Поиск " << needles[i] << "..." << endl;
  18.         if (binary_search(haystack, haystack + SIZE_A, needles[i]))
  19.             cout << "Найдено " << needles[i] << endl;
  20.         else
  21.             cout << "Не найдено!" << endl;
  22.     }
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement