Advertisement
Alaricy

города на первый ряд букв пизжено

Jan 17th, 2023
1,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <utility>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. template <typename RandomIt>
  10. pair<RandomIt, RandomIt> FindStartsWith(RandomIt range_begin, RandomIt range_end, string prefix) {
  11.     // напишите реализацию
  12.     auto result = equal_range(range_begin,range_end,prefix,[length = prefix.length()](const string& lhs,const string& rhs){return lhs.compare(0,length,rhs, 0, length) < 0;});
  13.     return result;
  14. }
  15.  
  16. int main() {
  17.     const vector<string> sorted_strings = {"moscow", "motovilikha", "murmansk"};
  18.     const auto mo_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), "mo");
  19.     for (auto it = mo_result.first; it != mo_result.second; ++it) {
  20.         cout << *it << " ";
  21.     }
  22.     cout << endl;
  23.     const auto mt_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), "mt");
  24.     cout << (mt_result.first - begin(sorted_strings)) << " " << (mt_result.second - begin(sorted_strings)) << endl;
  25.     const auto na_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), "na");
  26.     cout << (na_result.first - begin(sorted_strings)) << " " << (na_result.second - begin(sorted_strings)) << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement