Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 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. int counter = 0;
  14.  
  15. while (counter < numberOfTowns)
  16. {
  17.  
  18.     string cityName;
  19.     double minTemp, maxTemp;
  20.  
  21.     cin >> cityName;
  22.     cin >> minTemp;
  23.     cin >> maxTemp;
  24.  
  25.     map <string, pair <double, double>>::iterator it = townsInfo.begin();
  26.  
  27.  
  28.         if (townsInfo.count(cityName) == 1)
  29.         {
  30.  
  31.                 if (townsInfo[cityName].first > minTemp)
  32.                 {
  33.                     townsInfo[cityName].first = minTemp;
  34.                 }
  35.  
  36.                 if (townsInfo[cityName].second < maxTemp)
  37.                 {
  38.                     townsInfo[cityName].second = maxTemp;
  39.                 }
  40.         } else
  41.         {
  42.             counter++;
  43.             townsInfo.insert ({cityName, pair <double, double> {minTemp, maxTemp}});
  44.         }
  45.  
  46. }
  47.  
  48. map <string, pair <double, double>>::iterator itr = townsInfo.begin();
  49.  
  50. for (itr; itr != townsInfo.end(); ++itr)
  51. {
  52.     cout << itr -> first << " " << itr -> second.first << " " << itr -> second.second << endl;
  53. }
  54.  
  55.  
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement