-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.31.cpp
47 lines (43 loc) · 1.13 KB
/
11.31.cpp
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
38
39
40
41
42
43
44
45
46
47
#include <map>
#include <iostream>
#include <string>
using std::multimap;
using std::string;
using std::cout;
using std::endl;
using std::cin;
std::ostream &print(std::ostream &os, const multimap<string, string> &mm) {
string prevAuth;
bool first = true;
for (multimap<string, string>::const_iterator it = mm.cbegin(); it != mm.cend(); ++it) {
if (it->first != prevAuth) {
if (!first) {
os << '\n';
} else {
first = false;
}
os << it->first << ": " << it->second;
} else {
os << ' ' << it->second;
}
prevAuth = it->first;
}
return os;
}
void prompt(multimap<string, string> &mm) {
string removeKey;
cout << "\nEnter key to remove: ";
cin >> removeKey;
multimap<string, string>::iterator found = mm.find(removeKey);
if (found != mm.end()) {
mm.erase(found);
}
}
int main() {
multimap<string, string> authors = {{"A", "bookAC"},{"B", "bookBB"},{"C", "bookC"},{"A", "bookAB"},{"D", "bookD"},{"B", "bookBA"},{"E", "bookE"},{"A", "bookAA"},{"F", "bookF"},{"G", "bookGB"},{"G", "bookGA"},{"G", "bookGC"}};
while (authors.cbegin() != authors.cend() && cin) {
print(cout, authors);
prompt(authors);
}
return 0;
}