Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using std::cin;
- using std::cout;
- using std::endl;
- using std::vector;
- using std::string;
- struct course
- {
- int id = 0;
- vector<string> students{};
- };
- void fill_in(course* c)
- {
- // заполняем структуру
- cout << "enter id: ";
- cin >> c->id;
- int count;
- cout << "enter count of students: ";
- cin >> count;
- for (int i = 0; i < count; i++)
- {
- string buf{};
- cout << "enter name of student: ";
- cin >> buf;
- c->students.push_back(buf);
- }
- }
- void show(const course& c)
- {
- cout << "id: " << c.id << endl;
- cout << "students" << endl;
- for (string a: c.students)
- cout << a << endl;
- }
- int count(const course c)
- {
- return c.students.size();
- }
- bool compare(const course &first, const course &second)
- {
- // для убывания
- return first.students.size() > second.students.size();
- }
- int main()
- {
- int numb = 0;
- cout << "enter number of courses: ";
- cin >> numb;
- vector<course> courses;
- for (int i = 0; i < numb; i++)
- {
- course *c = new course;
- fill_in(c);
- courses.push_back(*c);
- }
- cout << courses.size() << endl;
- std::sort(courses.begin() ,courses.end(), compare);
- for (course a: courses)
- show(a);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement