Advertisement
black_canary_

Map - Car Program

Jan 19th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include <map>
  4. #include <iterator>
  5. #include <utility>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int numCars;
  11.     cin >> numCars;
  12.  
  13.     map<string, pair<string,int>> mymap = {};
  14.     string made = "", model = "";
  15.     int year = 0;
  16.  
  17.     for (int i = 0; i < numCars; i++)
  18.     {
  19.       cin >> made;
  20.       cin >> model;
  21.       cin >> year;
  22.  
  23.       mymap.insert(make_pair(made,make_pair(model,year)));
  24.     }
  25.  
  26.     string options;
  27.     cin >> options;
  28.  
  29.     if (options == "1")
  30.     {
  31.         cin >> made;
  32.  
  33.        for(auto it = mymap.cbegin(); it != mymap.cend(); ++it)
  34.        {
  35.            if (made == it->first)
  36.            {
  37.            cout << it->first << " " << it->second.first<< " " << it->second.second << endl;
  38.            }
  39.        }
  40.     }
  41.     if (options == "2")
  42.     {
  43.        for(auto it = mymap.cbegin(); it != mymap.cend(); ++it)
  44.        {
  45.            cout << it->first << " " << it->second.first<< " " << it->second.second << endl;
  46.        }
  47.     }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement