allia

поиск среди слов

Oct 20th, 2020 (edited)
951
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. int poisk (string *arr, string znach, int left, int right)
  8. {
  9.  int i = 0;
  10. while (left < right)
  11. {
  12.   i = (left + right) / 2;
  13.   if (arr[i] < znach)
  14.     left = i+1;
  15.   else right = i;
  16. }
  17.  
  18. if (arr[right] == znach)
  19. return right+1;
  20. return -1;
  21. }
  22.  
  23. int main()
  24. {
  25.   int n = 0, m = 0;
  26.   scanf("%d", &n);
  27.  
  28.   string buffer;
  29.  
  30.   string *arr = new string[n];
  31.  
  32.   for (int i = 0; i < n; i++)
  33.    cin >> arr[i];
  34.  
  35. scanf("%d", &m);
  36.  
  37. for (int i = 0; i < m; i++)
  38. {
  39.   cin >> buffer;
  40.   cout << poisk (arr, buffer, 0, n-1) << endl;
  41. }
  42. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×