Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.  
  9. int numberOfTowns;
  10. cin >> numberOfTowns;
  11.  
  12. map <string, pair <double, double>> townsInfo;
  13.  
  14. while (townsInfo.size() != numberOfTowns)
  15. {
  16.  
  17.     string cityName;
  18.     double minTemp, maxTemp;
  19.  
  20.     cin >> cityName;
  21.     cin >> minTemp;
  22.     cin >> maxTemp;
  23.  
  24.     map <string, pair <double, double>>::iterator it = townsInfo.begin();
  25.  
  26.  
  27.         if (townsInfo.count(cityName) == 1)
  28.         {
  29.  
  30.                 if (townsInfo[cityName].first > minTemp)
  31.                 {
  32.                     townsInfo[cityName].first = minTemp;
  33.                 }
  34.  
  35.                 if (townsInfo[cityName].second < maxTemp)
  36.                 {
  37.                     townsInfo[cityName].second = maxTemp;
  38.                 }
  39.         } else
  40.         {
  41.             townsInfo.insert ({cityName, pair <double, double> {minTemp, maxTemp}});
  42.         }
  43.  
  44. }
  45.  
  46. map <string, pair <double, double>>::iterator itr = townsInfo.begin();
  47.  
  48. for (itr; itr != townsInfo.end(); ++itr)
  49. {
  50.     cout << itr -> first << " " << itr -> second.first << " " << itr -> second.second << endl;
  51. }
  52.  
  53.  
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement