AlexG2230954

Untitled

Apr 13th, 2022 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <map>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct FullName {
  9.     string name;
  10.     string surname;
  11. };
  12.  
  13. bool operator < (const FullName & lhs, const FullName & rhs) {
  14.     if(lhs.surname != rhs.surname)
  15.         return lhs.surname < rhs.surname;
  16.    
  17.     return lhs.name < rhs.name;
  18. }
  19.  
  20. istream & operator >> (istream & inp, FullName & full_name) {
  21.     inp >> full_name.name >> full_name.surname;
  22.     return inp;
  23. }
  24.  
  25. struct BirthDate {
  26.     int day;
  27.     int month;
  28.     int year;
  29. };
  30.  
  31. bool operator < (const BirthDate & lhs, const BirthDate & rhs) {
  32.     if(lhs.year != rhs.year)
  33.         return lhs.year < rhs.year;
  34.    
  35.     if(lhs.month != rhs.month)
  36.         return lhs.month < rhs.month;
  37.    
  38.     return lhs.day < rhs.day;
  39. }
  40.  
  41. bool operator != (const BirthDate & lhs, const BirthDate & rhs) {
  42.     return (lhs < rhs) || (rhs < lhs);
  43. }
  44.  
  45. istream & operator >> (istream & inp, BirthDate & birth_date) {
  46.     inp >> birth_date.day >> birth_date.month >> birth_date.year;
  47.     return inp;
  48. }
  49.  
  50. struct Enrolle {
  51.     FullName full_name;
  52.     BirthDate birth_date;
  53.     int score;
  54.     queue<string> universities;
  55. };
  56.  
  57. bool operator < (const Enrolle & lhs, const Enrolle & rhs) {
  58.     if(lhs.score != rhs.score)
  59.         return lhs.score < rhs.score;
  60.    
  61.     if(lhs.birth_date != rhs.birth_date)
  62.         return lhs.birth_date < rhs.birth_date;
  63.    
  64.     return lhs.full_name < rhs.full_name;
  65. }
  66.  
  67. struct University {
  68.     int seats;
  69.     queue<FullName> received;
  70. };
  71.  
  72. int main() {
  73.     int n;
  74.     map<string, University> universities;
  75.     vector<Enrolle> enrolles;
  76.  
  77.     cin >> n;
  78.     while(n--) {
  79.         string name;
  80.         University university;
  81.  
  82.         cin >> name >> university.seats;
  83.         universities[name] = university;
  84.     }
  85.  
  86.     cin >> n;
  87.     enrolles.resize(n);
  88.  
  89.     for(Enrolle & enrolle : enrolles) {
  90.         int m;
  91.         string university;
  92.  
  93.         cin >> enrolle.full_name >> enrolle.birth_date >> enrolle.score;
  94.         cin >> m;
  95.  
  96.         while(m--) {
  97.             cin >> university;
  98.             enrolle.universities.push(university);
  99.         }
  100.     }
  101.  
  102.     sort(enrolles.begin(), enrolles.end());
  103.  
  104.     for(int i = enrolles.size() - 1; i >= 0; i--) {
  105.         Enrolle & enrolle = enrolles[i];
  106.  
  107.         while(!enrolle.universities.empty()) {
  108.             string name = enrolle.universities.front();
  109.             enrolle.universities.pop();
  110.  
  111.             if(universities.count(name) > 0 && universities[name].seats > 0) {
  112.                 universities[name].received.push(enrolle.full_name);
  113.                 universities[name].seats--;
  114.                 break;
  115.             }
  116.         }
  117.     }
  118.  
  119.     for(auto university : universities) {
  120.         string name = university.first;
  121.         queue<FullName> received = university.second.received;
  122.  
  123.         cout << name;
  124.  
  125.         while(!received.empty()) {
  126.             cout << "\t" << received.front().name << " " << received.front().surname;
  127.             received.pop();
  128.         }
  129.  
  130.         cout << endl;
  131.     }
  132. }
Add Comment
Please, Sign In to add comment