#include <iostream>
#include <map>
using namespace std;
typedef std::string Str;
typedef std::map<Str,size_t> Data;
typedef Data::const_iterator It;
Data phonebook;
void PrintRange(const Data& book, const Str& range);
int main() {
phonebook["Pupkin"] = 1111111;
phonebook["Pupkin1"] = 1111111;
phonebook["Pupkin11"] = 1111111;
phonebook["Pupkin1f"] = 1111111;
phonebook["Pupkin222"] = 1111111;
phonebook["Pupkin23a"] = 1111111;
cout<<"contents of phonebook:\n";
for(It it = phonebook.begin(); it!= phonebook.end(); ++it)
cout<<"record: "<< it->first<<" : "<<it->second<<endl;
//--------------
//ищем все ключи, которые содержат в себе диапазон:
const Str range = "Pupkin1";
//--------------
PrintRange(phonebook, range);
return 0;
}
void PrintRange(const Data& book, const Str& range)
{
cout<<"view all the abonents containing part of the name: "<<range<<endl;
It beg = book.lower_bound(range);
const Str::value_type elem = range[range.length()-1]+1;
Str end_key = range;
end_key[end_key.length()-1]=elem;
const It end = book.lower_bound(end_key);
It it = beg;
while(it!=end)
{
cout<<"record: "<< it->first<<" : "<<it->second<<endl;
++it;
}
cout<<"number of abonents : "<<std::distance(beg, end)<<endl;
}