Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<map>
  5. #include<unordered_map>
  6. #include<algorithm>
  7.  
  8. using namespace std;
  9.  
  10. struct applicant {
  11.     string name, surname;
  12.     int birth_day, birth_month, birth_year, score;
  13.     vector<string> universities;
  14.     void read() {
  15.         cin >> name >> surname >> birth_day >> birth_month >> birth_year >> score;
  16.         int k;
  17.         cin >> k;
  18.         universities.resize(k);
  19.         for (int i = 0; i < k; i++)
  20.             cin >> universities[i];
  21.         return;
  22.     }
  23.     tuple<int, int, int, int, string, string> to_tuple() const {
  24.         return make_tuple(-score, birth_year, birth_month, birth_day, surname, name);
  25.     }
  26.     bool operator < (const applicant& other) const {
  27.         return to_tuple() < other.to_tuple();
  28.     }
  29. };
  30.  
  31. bool cmp_students(const pair<string, string> &a, const pair<string, string> &b) {
  32.     return make_tuple(a.second, a.first) < make_tuple(b.second, b.first);
  33. }
  34.  
  35. int main() {
  36.     unordered_map<string, int> quotas;
  37.     int universities_number;
  38.     cin >> universities_number;
  39.     for (int i = 0; i < universities_number; i++) {
  40.         string name;
  41.         cin >> name;
  42.         cin >> quotas[name];
  43.     }
  44.     int applicants_number;
  45.     cin >> applicants_number;
  46.     vector<applicant> applicants(applicants_number);
  47.     for (int i = 0; i < applicants_number; i++) {
  48.          applicants[i].read();
  49.     }
  50.     map<string, vector<pair<string, string>>> admission;
  51.     for (const auto& a : applicants) {
  52.         for (const auto& university : a.universities)
  53.             if (admission[university].size() < quotas[university]) {
  54.                 admission[university].emplace_back(a.name, a.surname);
  55.                 break;
  56.             }
  57.     }
  58.     for (auto& [university, students] : admission) {
  59.         cout << university;
  60.         sort(students.begin(), students.end(), cmp_students);
  61.         for (const auto& student : students)
  62.             cout << '\t' << student.first << ' ' << student.second;
  63.         cout << '\n';
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement