Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <unordered_map>
  4. #include <unordered_set>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. bool comp(const pair<string, int> &a, const pair<string, int> &b) {
  10. if (a.second != b.second) {
  11. return a.second > b.second;
  12. }
  13. return a.first < b.first;
  14. }
  15.  
  16. int main() {
  17. int n, m, k;
  18. string a, b;
  19. unordered_map<string, int> minn;
  20. unordered_map<string, unordered_set<string> > pupil;
  21. cin >> n;
  22. for (int i = 0; i < n; ++i) {
  23. cin >> a >> k;
  24. minn[a] = k;
  25. }
  26. cin >> m;
  27. for (int i = 0; i < m; ++i) {
  28. cin >> a >> b >> k;
  29. pupil[a].insert("0");
  30. if (minn.find(b) != minn.end() && k >= minn[b]) {
  31. pupil[a].insert(b);
  32. }
  33. }
  34. vector<pair<string, int> > v;
  35. for (auto i = pupil.begin(); i != pupil.end(); ++i) {
  36. v.push_back({i->first, i->second.size() - 1});
  37. }
  38. sort(v.begin(), v.end(), comp);
  39. for (auto i = v.begin(); i != v.end(); ++i) {
  40. cout << i->first << ' ' << i->second << '\n';
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement