StoneHaos

nastya2

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