Advertisement
chzchz

Untitled

Mar 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <utility>
  5. #include <algorithm>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. template<typename RandomIt>
  11. pair<RandomIt, RandomIt> FindStartsWith(RandomIt range_begin, RandomIt range_end, string prefix) {
  12.     auto result = equal_range(range_begin, range_end, prefix, [](const string &lhs, const string &rhs) {
  13.         return lhs < rhs;
  14.     });
  15.     return result;
  16. }
  17.  
  18. int main() {
  19.     const vector<string> sorted_strings = {"moscow", "motovilikha", "murmansk"};
  20.     auto result = FindStartsWith(begin(sorted_strings), end(sorted_strings), "mo");
  21.     cout << (result.first - begin(sorted_strings)) << ' ' << (result.second - begin(sorted_strings));
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement