Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <utility>
- #include <vector>
- using namespace std;
- bool compare(const pair<string, int>& a, const pair<string, int>& b) {
- return (a.second > b.second) || (a.second == b.second && a.first < b.first);
- }
- int main() {
- long long n;
- cin >> n;
- map<string, long long> courses;
- for (auto i = 0; i < n; ++i) {
- string subj;
- long long min_mark;
- cin >> subj >> min_mark;
- courses[subj] = min_mark;
- }
- long long m;
- cin >> m;
- map<string, set<string>> students;
- for (auto i = 0; i < m; ++i) {
- string name, subj;
- long long mark;
- cin >> name >> subj >> mark;
- if (students.count(name) == 0) {
- students[name] = {};
- }
- if (courses.count(subj) != 0) {
- if (mark >= courses[subj]) {
- students[name].insert(subj);
- }
- }
- }
- vector<pair<string, int>> passed;
- for (const pair<string, set<string>> student : students) {
- passed.push_back({student.first, student.second.size()});
- }
- sort(passed.begin(), passed.end(), compare);
- for (const auto& student : passed) {
- cout << student.first
- << " "
- << student.second
- << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement