Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.2 kB
0
Indexable
Never
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Student {
    string name;
    string faculty;
    string group;
    int absences;
};

bool sortByAbsences(const Student& a, const Student& b) {
    return a.absences > b.absences;
}

int main() {
    vector<Student> students = {
            {"Ivanov Ivan", "IT", "IT-01", 5},
            {"Petrov Petro", "IT", "IT-02", 3},
            {"Sidorov Sidor", "Economics", "ECO-01", 7},
            {"Kuznetsov Kuzma", "Economics", "ECO-02", 2},
            {"Zaytsev Zakhar", "Law", "LAW-01", 4},
            {"Golubev Grigory", "Law", "LAW-02", 6},
            {"Semenov Semen", "Philosophy", "PHI-01", 1},
            {"Romanov Roman", "Philosophy", "PHI-02", 8},
            {"Dmitriev Dmitry", "Physics", "PHY-01", 2},
            {"Andreev Andrey", "Physics", "PHY-02", 9},
    };

    sort(students.begin(), students.end(), sortByAbsences);

    cout << "Top 10 students with most absences:" << endl;
    for (int i = 0; i < 10; i++) {
        cout << students[i].name << " (" << students[i].faculty << ", " << students[i].group << ") - " << students[i].absences << " absences" << endl;
    }

    return 0;
}