Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <utility>
- #include <string>
- #include <vector>
- #include <tuple>
- #include <algorithm>
- struct Student {
- uint32_t score, day, mon, year;
- std::string name, surname;
- std::vector<std::string> univ;
- Student(const std::string &_name, const std::string &_surname,
- uint32_t _day, uint32_t _mon, uint32_t _year,
- uint32_t _score)
- : name(_name),
- surname(_surname),
- day(_day),
- mon(_mon),
- year(_year),
- score(_score) {}
- };
- int main() {
- std::vector<Student> st;
- std::map<std::string, std::pair<int, std::vector<Student>>> universities;
- uint32_t n;
- std::cin >> n;
- for (uint32_t i = 0; i < n; ++i) {
- std::string name;
- uint32_t thresh;
- std::cin >> name >> thresh;
- universities[name] = {thresh, std::vector<Student>()};
- }
- uint32_t m;
- std::cin >> m;
- st.reserve(m);
- for (uint32_t i = 0; i < m; ++i) {
- uint32_t day, mon, year, score, k;
- std::vector<std::string> univ;
- std::string name, surname;
- std::cin >> name >> surname >> day >> mon >>
- year >> score >> k;
- st.emplace_back(name, surname, day, mon, year, score);
- st[i].univ.reserve(k);
- for (uint32_t j = 0; j < k; ++j) {
- std::string wish;
- std::cin >> wish;
- st[i].univ.emplace_back(wish);
- }
- }
- sort(st.begin(), st.end(), [](const Student &a, const Student &b) {
- int a_score = -a.score;
- int b_score = -b.score;
- return std::tie(a_score, a.year, a.mon, a.day, a.surname, a.name) <
- std::tie(b_score, b.year, b.mon, b.day, b.surname, b.name);
- });
- for (auto stud : st) {
- for (auto name : stud.univ)
- if (universities[name].first > 0) {
- --universities[name].first;
- universities[name].second.push_back(stud);
- break;
- }
- }
- for (auto pr : universities) {
- std::cout << pr.first << '\t';
- sort(pr.second.second.begin(), pr.second.second.end(),
- [](const Student &a, const Student &b) {
- return tie(a.surname, a.name, a.year, a.mon, a.day) <
- tie(b.surname, b.name, b.year, b.mon, b.day);
- });
- for (auto stud : pr.second.second)
- std::cout << stud.name << ' ' << stud.surname << '\t';
- std::cout << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement