kolioi

44. Car Program C++

Dec 20th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct
  9. {
  10.     string make;
  11.     string model;
  12.     int year;
  13. } Car;
  14.  
  15. int main()
  16. {
  17.     int n;
  18.     cin >> n;
  19.  
  20.     vector<Car> cars;
  21.     for (int i = 0; i < n; ++i)
  22.     {
  23.         Car new_car;
  24.         cin >> new_car.make >> new_car.model >> new_car.year;
  25.         cars.push_back(new_car);
  26.     }
  27.  
  28.     int choice;
  29.     cin >> choice;
  30.  
  31.     if (1 == choice)
  32.     {
  33.         string make;
  34.         cin >> make;
  35.         for (auto car : cars)
  36.             if (make == car.make)
  37.                 cout << car.make << " " << car.model << " " << car.year << endl;
  38.     }
  39.     else if(2 == choice)
  40.     {
  41.         sort(cars.begin(), cars.end(), [](Car& a, Car& b) {return a.make < b.make; });
  42.  
  43.         for (auto car : cars)
  44.             cout << car.make << " " << car.model << " " << car.year << endl;
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment