-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap1.cpp
More file actions
37 lines (32 loc) · 692 Bytes
/
map1.cpp
File metadata and controls
37 lines (32 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <map>
#include <iostream>
#include <algorithm>
using std::map;
using std::cout;
using std::endl;
using std::pair;
using std::string;
using std::vector;
void PrintNumber(int n)
{
cout << ' ' << n;
}
void PrintEntry(const pair <string, vector <int>> &e)
{
cout << e.first << ':';
for_each(e.second.cbegin(), e.second.cend(), PrintNumber);
cout << endl;
}
int main(void)
{
const map <string, vector <int>> PhoneBook
{
{ "Ivan", { 1, 3, 5, 7, 9 }},
{ "Petr", { 2, 4, 6, 8, 10 }},
{ "Vasily", { 3, 6, 9, 12, 15 }},
{ "Dmitry", { 4, 8, 12, 16, 20 }},
{ "Alexey", { 5, 10, 15, 20, 25 }}
};
for_each(PhoneBook.cbegin(), PhoneBook.cend(), PrintEntry);
return int();
}