Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <map>
- #include <algorithm>
- using namespace std;
- struct FullName {
- string name;
- string surname;
- };
- bool operator < (const FullName & lhs, const FullName & rhs) {
- if(lhs.surname != rhs.surname)
- return lhs.surname < rhs.surname;
- return lhs.name < rhs.name;
- }
- istream & operator >> (istream & inp, FullName & full_name) {
- inp >> full_name.name >> full_name.surname;
- return inp;
- }
- struct BirthDate {
- int day;
- int month;
- int year;
- };
- bool operator < (const BirthDate & lhs, const BirthDate & rhs) {
- if(lhs.year != rhs.year)
- return lhs.year < rhs.year;
- if(lhs.month != rhs.month)
- return lhs.month < rhs.month;
- return lhs.day < rhs.day;
- }
- bool operator != (const BirthDate & lhs, const BirthDate & rhs) {
- return (lhs < rhs) || (rhs < lhs);
- }
- istream & operator >> (istream & inp, BirthDate & birth_date) {
- inp >> birth_date.day >> birth_date.month >> birth_date.year;
- return inp;
- }
- struct Enrolle {
- FullName full_name;
- BirthDate birth_date;
- int score;
- queue<string> universities;
- };
- bool operator < (const Enrolle & lhs, const Enrolle & rhs) {
- if(lhs.score != rhs.score)
- return lhs.score < rhs.score;
- if(lhs.birth_date != rhs.birth_date)
- return lhs.birth_date < rhs.birth_date;
- return lhs.full_name < rhs.full_name;
- }
- struct University {
- int seats;
- queue<FullName> received;
- };
- int main() {
- int n;
- map<string, University> universities;
- vector<Enrolle> enrolles;
- cin >> n;
- while(n--) {
- string name;
- University university;
- cin >> name >> university.seats;
- universities[name] = university;
- }
- cin >> n;
- enrolles.resize(n);
- for(Enrolle & enrolle : enrolles) {
- int m;
- string university;
- cin >> enrolle.full_name >> enrolle.birth_date >> enrolle.score;
- cin >> m;
- while(m--) {
- cin >> university;
- enrolle.universities.push(university);
- }
- }
- sort(enrolles.begin(), enrolles.end());
- for(int i = enrolles.size() - 1; i >= 0; i--) {
- Enrolle & enrolle = enrolles[i];
- while(!enrolle.universities.empty()) {
- string name = enrolle.universities.front();
- enrolle.universities.pop();
- if(universities.count(name) > 0 && universities[name].seats > 0) {
- universities[name].received.push(enrolle.full_name);
- universities[name].seats--;
- break;
- }
- }
- }
- for(auto university : universities) {
- string name = university.first;
- queue<FullName> received = university.second.received;
- cout << name;
- while(!received.empty()) {
- cout << "\t" << received.front().name << " " << received.front().surname;
- received.pop();
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment