Exercise 11.27
For Multimap, counting the number of occurrences of a keyword will be good, but it is more appropriate for a map to find a keyword;
Exercise 11.28
1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One A intMain () - { -vector<int> VEC = {1,2,3,4,5 }; thevector<int> vec2 = {6,7,8,9,Ten }; - strings ="T"; - stringS1 ="B"; -map<string, vector<int>> m ={{S,vec},{s1,vec2}}; +Auto it = M.find ("T"); -cout << (*it). First <<" "; + for(Auto &i: (*it). Second) Acout << i <<" "; atcout <<Endl; -System"Pause"); - return 0; -}
Exercise 11.29
Upper_bound: The insertion position iterator that points to the found element without affecting sorting;
Lower_bound: Ibid.
Equal_range: An iterator pair, with two iterators pointing to where the element should be inserted
Exercise 11.30
POS is an iterator pair, with two iterators pointing to the first position of the lookup element and the position after the last element of the lookup element, Pos.first refers to its first iterator, which is the keyword after the dereference, and in the call second is the value of the keyword;
Exercise 11.31
1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One A intMain () - { -multimap<string,string>authors; the stringstr, str1; - stringbook{"ASD"}; - while(Cin >> STR >>str1) - { + Authors.insert ({str, str1}); - } + authors.erase (book); A for(auto c:authors) at { -cout << C.first <<" "<< C.second <<Endl; - } -System"Pause"); - return 0; -}
Add a method, the problem is not to use the Find function
1#include <iostream>2#include <string>3#include <Set>4#include <map>5#include <algorithm>6#include <vector>7#include <algorithm>8#include <iterator>9 Ten using namespacestd; One A intMain () - { -multimap<string,string>authors; the stringstr, str1; - stringBook"ASD"); - while(Cin >> STR >>str1) - { + Authors.insert ({str, str1}); - } +Auto it =authors.find (book); A for(; (*it). First = =Book ;) atit = authors.erase (it);//Note the type returned here erase - for(auto c:authors) - { -cout << C.first <<" "<< C.second <<Endl; - } -System"Pause"); in return 0; -}
Exercise 11.32
See above
C++primer 11.3.5 exercises