Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- void PrintMap(const map <int, string>& m)
- {
- cout << "Size = " << m.size() << endl;
- for (auto item : m)
- {
- cout << item.first << ": " << item.second << endl;
- }
- }
- void PrintReversedMap(const map <string, int>& m)
- {
- cout << "Size = " << m.size() << endl;
- for (auto item : m)
- {
- cout << item.first << ": " << item.second << endl;
- }
- }
- map<string, int> BuildReversedMap(const map<int, string>& m)
- {
- map<string, int> result;
- for (auto item : m)
- {
- result[item.second] = item.first;
- }
- return result;
- }
- int main()
- {
- map<int, string> events;
- events[1950] = "Bjarne Stroustrup's birth";
- events[1941] = "Dennis Ritchie's birth";
- events[1970] = "UNIX epoch start";
- PrintMap(events);
- cout << events[1950] << endl;
- events.erase(1970); // принимает ключ, который хотим удалить вместе с его значением
- PrintMap(events);
- //PrintReversedMap(BuildReversedMap(events));
- map<string, int> event_for_year = BuildReversedMap(events);
- cout << event_for_year["Bjarne Stroustrup's birth"];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement