SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <vector> | |
| 2 | #include <algorithm> | |
| 3 | #include <iostream> | |
| 4 | #include <set> | |
| 5 | ||
| 6 | using namespace std; | |
| 7 | ||
| 8 | template <typename RandomIt> | |
| 9 | pair<RandomIt, RandomIt> FindStartsWith(RandomIt range_begin, RandomIt range_end, char prefix) {
| |
| 10 | // напишите реализацию | |
| 11 | auto lower = lower_bound(range_begin, range_end, string(1, prefix)); | |
| 12 | auto upper = lower_bound(range_begin, range_end, string(1, (prefix + 1))); | |
| 13 | return make_pair(lower, upper); | |
| 14 | } | |
| 15 | int main() {
| |
| 16 | const vector<string> sorted_strings = {"moscow", "murmansk", "vologda"};
| |
| 17 | const auto m_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), 'm'); | |
| 18 | for (auto it = m_result.first; it != m_result.second; ++it) {
| |
| 19 | cout << *it << " "; | |
| 20 | } | |
| 21 | cout << endl; | |
| 22 | const auto p_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), 'p'); | |
| 23 | cout << (p_result.first - begin(sorted_strings)) << " " << (p_result.second - begin(sorted_strings)) << endl; | |
| 24 | const auto z_result = FindStartsWith(begin(sorted_strings), end(sorted_strings), 'z'); | |
| 25 | cout << (z_result.first - begin(sorted_strings)) << " " << (z_result.second - begin(sorted_strings)) << endl; | |
| 26 | return 0; | |
| 27 | } |