Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. int main() {
  8.   std::map<std::string, int> min_subj;
  9.   std::map<std::string, std::map<std::string, int>> stud_max;
  10.  
  11.   int N;
  12.   std::cin >> N;
  13.  
  14.   for (int i = 0; i < N; i++) {
  15.     std::string sname;
  16.     int ps;
  17.     std::cin >> sname >> ps;
  18.     min_subj[sname] = ps;
  19.   }
  20.  
  21.   int M;
  22.   std::cin >> M;
  23.   for (int i = 0; i < M; i++) {
  24.     std::string name;
  25.     std::string subj;
  26.     if (!min_subj.count(subj)) {
  27.       if (!stud_max.count(name))
  28.         stud_max.insert(std::make_pair(name, std::map<std::string, int>()));
  29.       continue;
  30.     }
  31.     int pts;
  32.     std::cin >> name >> subj >> pts;
  33.     (stud_max[name])[subj] = pts;
  34.   }
  35.  
  36.   std::vector<std::pair<std::string, int>> mvec;
  37.   for (auto& stud : stud_max) {
  38.     auto& name = stud.first;
  39.     auto& mmap = stud.second;
  40.    
  41.     int k = 0;
  42.     for (auto& s : mmap)
  43.       if (s.second >= min_subj[s.first])
  44.         k++;
  45.     mvec.push_back(std::make_pair(name, k));
  46.   }
  47.   std::sort(mvec.begin(), mvec.end(), [](const std::pair<std::string, int>& l, std::pair<std::string, int> r) {
  48.     if (l.second != r.second)
  49.       return l.second > r.second;
  50.     else
  51.       return l.first < r.first;
  52.   });
  53.  
  54.   for(auto& r : mvec)
  55.     std::cout << r.first << " " << r.second << std::endl;
  56.  
  57.   return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement