daily pastebin goal
46%
SHARE
TWEET

Untitled

chzchz Mar 25th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top