Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- int main ()
- {
- int numberOfTowns;
- cin >> numberOfTowns;
- map <string, pair <double, double>> townsInfo;
- int counter = 0;
- while (counter < numberOfTowns)
- {
- string cityName;
- double minTemp, maxTemp;
- cin >> cityName;
- cin >> minTemp;
- cin >> maxTemp;
- map <string, pair <double, double>>::iterator it = townsInfo.begin();
- if (townsInfo.count(cityName) == 1)
- {
- if (townsInfo[cityName].first > minTemp)
- {
- townsInfo[cityName].first = minTemp;
- }
- if (townsInfo[cityName].second < maxTemp)
- {
- townsInfo[cityName].second = maxTemp;
- }
- } else
- {
- counter++;
- townsInfo.insert ({cityName, pair <double, double> {minTemp, maxTemp}});
- }
- }
- map <string, pair <double, double>>::iterator itr = townsInfo.begin();
- for (itr; itr != townsInfo.end(); ++itr)
- {
- cout << itr -> first << " " << itr -> second.first << " " << itr -> second.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement