Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
57
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 <set>
  4. #include <algorithm>
  5. #include <utility>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. bool compare(const pair<string, int>& a, const pair<string, int>& b) {
  11.     return (a.second > b.second) || (a.second == b.second && a.first < b.first);
  12. }
  13.  
  14. int main() {
  15.     long long n;
  16.     cin >> n;
  17.  
  18.     map<string, long long> courses;
  19.     for (auto i = 0; i < n; ++i) {
  20.         string subj;
  21.         long long min_mark;
  22.         cin >> subj >> min_mark;
  23.         courses[subj] = min_mark;
  24.     }
  25.  
  26.     long long m;
  27.     cin >> m;
  28.  
  29.     map<string, set<string>> students;
  30.     for (auto i = 0; i < m; ++i) {
  31.         string name, subj;
  32.         long long mark;
  33.         cin >> name >> subj >> mark;
  34.  
  35.         if (students.count(name) == 0) {
  36.             students[name] = {};
  37.         }
  38.         if (courses.count(subj) != 0) {
  39.             if (mark >= courses[subj]) {
  40.                 students[name].insert(subj);
  41.             }
  42.         }
  43.     }
  44.  
  45.     vector<pair<string, int>> passed;
  46.     for (const pair<string, set<string>> student : students) {
  47.         passed.push_back({student.first, student.second.size()});
  48.     }
  49.  
  50.     sort(passed.begin(), passed.end(), compare);
  51.  
  52.     for (const auto& student : passed) {
  53.         cout << student.first
  54.              << " "
  55.              << student.second
  56.              << endl;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement