StoneHaos

misha_shik2

Oct 7th, 2020
564
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <list>
  3. #include <time.h>
  4. #include <map>
  5. #include <utility>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. void print(string s, multimap<int, float> mp) {
  11.     cout << s;
  12.     for (auto it = mp.begin(); it != mp.end(); ++ it)
  13.         cout << it->first << ":" << it->second << "\n";
  14. }
  15.  
  16. int main(void) {
  17.     time_t t = time(NULL);
  18.     srand(t);
  19.     cout << "t = " << t << endl;
  20.  
  21.     int n;
  22.     cout << "Input length> ";
  23.     cin >> n;
  24.     multimap<int, float> mp;
  25.     cout << "\nMap:\n";
  26.     for (int i = 0; i < n; ++ i) {
  27.         int x = rand() % 100;
  28.         mp.insert(pair<int, float>(i, x));
  29.         cout << i << ":" << x << endl;
  30.     }
  31.  
  32. //1
  33.     multimap<int, float>::iterator iter = mp.begin();
  34.     for (auto it = mp.begin(); it != mp.end(); ++ it) {
  35.         if (it->second < iter->second)
  36.             iter = it;
  37.     }
  38.     mp.erase(iter);
  39.     print("\n(1)Map:\n", mp);
  40.  
  41. //2
  42.     int key;
  43.     cout << "Input key> ";
  44.     cin >> key;
  45.     iter = mp.find(key);
  46.     if (iter != mp.end())
  47.         mp.erase(iter);
  48.     print("\n(2)Map:\n", mp);
  49.  
  50. //3
  51.     iter = mp.begin();
  52.     for (auto it = mp.begin(); it != mp.end(); ++ it) {
  53.         if (it->second > iter->second)
  54.             iter = it;
  55.     }
  56.     for (auto it = mp.begin(); it != mp.end(); ++ it)
  57.         it->second *= iter->second;
  58.     print("\n(3)Map:\n", mp);
  59.     return 0;
  60. }
RAW Paste Data