Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <map>
- #include <string>
- using std::cout;
- using std::cin;
- using std::string;
- struct student {
- string name;
- string surname;
- int day;
- int month;
- int year;
- int score;
- int number;
- std::vector<string> university;
- };
- bool compare_entry(const student & student1, const student & student2) {
- if (student1.score != student2.score) {
- return student1.score > student2.score;
- } else if (student1.year != student2.year) {
- return (student1.year < student2.year);
- } else if (student1.month != student2.month) {
- return (student1.month < student2.month);
- } else if (student1.day != student2.day) {
- return (student1.day < student2.day);
- } else if (student1.surname != student2.surname) {
- return (student1.surname < student2.surname);
- }
- return (student1.name < student2.name);
- }
- bool compare_entry2(const string & string1, const string & string2) {
- return (string1 < string2);
- }
- int main() {
- int N, M;
- string call, name1, name2, day, month, year, date, sco, number, univ;
- std::vector<student> students, result;
- std::vector<string> universities, k;
- std::map<string, int> places;
- std::map<string, std::vector<string>> results;
- cin >> N;
- for (int i = 0; i < N; i++) {
- cin >> univ;
- cin >> number;
- places[univ] = stoi(number);
- universities.push_back(univ);
- }
- cin >> M;
- for (int i = 0; i < M; i++) {
- student stud;
- cin >> name1;
- cin >> name2;
- cin >> day;
- cin >> month;
- cin >> year;
- cin >> sco;
- cin >> number;
- stud.name = name1;
- stud.surname = name2;
- stud.day = std::stoi(day);
- stud.month = std::stoi(month);
- stud.year = std::stoi(year);
- stud.score = std::stoi(sco);
- stud.number = std::stoi(number);
- for (int j = 0; j < stud.number; j++) {
- cin >> univ;
- stud.university.push_back(univ);
- }
- students.push_back(stud);
- }
- std::sort(students.begin(), students.end(), compare_entry2);
- for (int i = 0; i < N; i++) {
- std::vector<string> empty = {};
- results[universities[i]] = empty;
- }
- for (int i = 0; i < M; i++) {
- for (int j = 0; j < students[i].number; j++) {
- if (places.at(students[i].university[j]) > 0) {
- places.at(students[i].university[j]) -= 1;
- k = results[students[i].university[j]];
- k.push_back(students[i].name + ' ' + students[i].surname);
- results.at(students[i].university[j]) = k;
- j = students[i].number;
- }
- }
- }
- std::sort(universities.begin(), universities.end());
- int j = 0;
- for (int i = 0; i < N; i++) {
- cout << universities[i];
- for (j = 0; j < results.at(universities[i]).size(); j++) {
- cout << '\t' << results.at(universities[i])[j];
- }
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement