Advertisement
in_chainz

Untitled

Jan 26th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <utility>
  4. #include <string>
  5. #include <vector>
  6. #include <tuple>
  7. #include <algorithm>
  8.  
  9. struct Student {
  10.     uint32_t score, day, mon, year;
  11.     std::string name, surname;
  12.     std::vector<std::string> univ;
  13.  
  14.     Student(const std::string &_name, const std::string &_surname,
  15.             uint32_t _day, uint32_t _mon, uint32_t _year,
  16.             uint32_t _score)
  17.             : name(_name),
  18.               surname(_surname),
  19.               day(_day),
  20.               mon(_mon),
  21.               year(_year),
  22.               score(_score) {}
  23. };
  24.  
  25. int main() {
  26.     std::vector<Student> st;
  27.     std::map<std::string, std::pair<int, std::vector<Student>>> universities;
  28.  
  29.     uint32_t n;
  30.     std::cin >> n;
  31.     for (uint32_t i = 0; i < n; ++i) {
  32.         std::string name;
  33.         uint32_t thresh;
  34.         std::cin >> name >> thresh;
  35.         universities[name] = {thresh, std::vector<Student>()};
  36.     }
  37.  
  38.     uint32_t m;
  39.     std::cin >> m;
  40.     st.reserve(m);
  41.     for (uint32_t i = 0; i < m; ++i) {
  42.         uint32_t day, mon, year, score, k;
  43.         std::vector<std::string> univ;
  44.         std::string name, surname;
  45.         std::cin >> name >> surname >> day >> mon >>
  46.                  year >> score >> k;
  47.         st.emplace_back(name, surname, day, mon, year, score);
  48.         st[i].univ.reserve(k);
  49.         for (uint32_t j = 0; j < k; ++j) {
  50.             std::string wish;
  51.             std::cin >> wish;
  52.             st[i].univ.emplace_back(wish);
  53.         }
  54.     }
  55.     sort(st.begin(), st.end(), [](const Student &a, const Student &b) {
  56.         int a_score = -a.score;
  57.         int b_score = -b.score;
  58.         return std::tie(a_score, a.year, a.mon, a.day, a.surname, a.name) <
  59.                std::tie(b_score, b.year, b.mon, b.day, b.surname, b.name);
  60.     });
  61.  
  62.     for (auto stud : st) {
  63.         for (auto name : stud.univ)
  64.             if (universities[name].first > 0) {
  65.                 --universities[name].first;
  66.                 universities[name].second.push_back(stud);
  67.                 break;
  68.             }
  69.     }
  70.  
  71.     for (auto pr : universities) {
  72.         std::cout << pr.first << '\t';
  73.         sort(pr.second.second.begin(), pr.second.second.end(),
  74.                   [](const Student &a, const Student &b) {
  75.                       return tie(a.surname, a.name, a.year, a.mon, a.day) <
  76.                              tie(b.surname, b.name, b.year, b.mon, b.day);
  77.                   });
  78.         for (auto stud : pr.second.second)
  79.             std::cout << stud.name << ' ' << stud.surname << '\t';
  80.         std::cout << std::endl;
  81.     }
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement