Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <time.h>
- #include <map>
- #include <utility>
- #include <string>
- using namespace std;
- void print(string s, multimap<int, float> mp) {
- cout << s;
- for (auto it = mp.begin(); it != mp.end(); ++ it)
- cout << it->first << ":" << it->second << "\n";
- }
- int main(void) {
- time_t t = time(NULL);
- srand(t);
- cout << "t = " << t << endl;
- int n;
- cout << "Input length> ";
- cin >> n;
- multimap<int, float> mp;
- cout << "\nMap:\n";
- for (int i = 0; i < n; ++ i) {
- int x = rand() % 100;
- mp.insert(pair<int, float>(i, x));
- cout << i << ":" << x << endl;
- }
- //1
- multimap<int, float>::iterator iter = mp.begin();
- for (auto it = mp.begin(); it != mp.end(); ++ it) {
- if (it->second < iter->second)
- iter = it;
- }
- mp.erase(iter);
- print("\n(1)Map:\n", mp);
- //2
- int key;
- cout << "Input key> ";
- cin >> key;
- iter = mp.find(key);
- if (iter != mp.end())
- mp.erase(iter);
- print("\n(2)Map:\n", mp);
- //3
- iter = mp.begin();
- for (auto it = mp.begin(); it != mp.end(); ++ it) {
- if (it->second > iter->second)
- iter = it;
- }
- for (auto it = mp.begin(); it != mp.end(); ++ it)
- it->second *= iter->second;
- print("\n(3)Map:\n", mp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement