Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <utility>
- #include <algorithm>
- using namespace std;
- template<typename RandomIt>
- pair<RandomIt, RandomIt> FindStartsWith(RandomIt range_begin, RandomIt range_end, string prefix) {
- auto result = equal_range(range_begin, range_end, prefix, [](const string &lhs, const string &rhs) {
- return lhs < rhs;
- });
- return result;
- }
- int main() {
- const vector<string> sorted_strings = {"moscow", "motovilikha", "murmansk"};
- auto result = FindStartsWith(begin(sorted_strings), end(sorted_strings), "mo");
- cout << (result.first - begin(sorted_strings)) << ' ' << (result.second - begin(sorted_strings));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement