Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef struct
- {
- string make;
- string model;
- int year;
- } Car;
- int main()
- {
- int n;
- cin >> n;
- vector<Car> cars;
- for (int i = 0; i < n; ++i)
- {
- Car new_car;
- cin >> new_car.make >> new_car.model >> new_car.year;
- cars.push_back(new_car);
- }
- int choice;
- cin >> choice;
- if (1 == choice)
- {
- string make;
- cin >> make;
- for (auto car : cars)
- if (make == car.make)
- cout << car.make << " " << car.model << " " << car.year << endl;
- }
- else if(2 == choice)
- {
- sort(cars.begin(), cars.end(), [](Car& a, Car& b) {return a.make < b.make; });
- for (auto car : cars)
- cout << car.make << " " << car.model << " " << car.year << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment