题目传送门
一道模拟题……
用一个 map
存储每个人的优先级因子,然后存进 vector
里进行排序。难点在于分辨 X 和 Y 与当前是什么操作。
不过需要注意,只要出现了名字就需要输出,且我们认为与你没关系的人不加分。
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <bits/stdc++.h> #define ll long long #define INF 1e9 using namespace std; string name; int n, cnt; map <string, int> mp; vector <pair <string, int>> ans; bool cmp(const pair <string, int> &x, const pair <string, int> &y) { if (x.second != y.second) return x.second > y.second; return x.first < y.first; } signed main() { ios :: sync_with_stdio(0); cin >> name >> n; cin.get(); for (int i = 1; i <= n; i++) { int j; string s, x, y, op; getline(cin, s); for (j = s.size() - 8; s[j] != ' '; j--) y += s[j]; reverse(y.begin(), y.end()); for (j = 0; s[j] != ' '; j++) x += s[j]; for (j++; s[j] != ' '; j++) op += s[j]; if (x != name and mp.find(x) == mp.end()) mp[x] = 0; if (y != name and mp.find(y) == mp.end()) mp[y] = 0; if (y == name) { if (op == "posted") mp[x] += 15; else if (op == "commented") mp[x] += 10; else mp[x] += 5; } if (x == name) { if (op == "posted") mp[y] += 15; else if (op == "commented") mp[y] += 10; else mp[y] += 5; } } for (auto v : mp) ans.push_back(make_pair(v.first, v.second)); sort(ans.begin(), ans.end(), cmp); for (auto v : ans) cout << v.first << "\n"; return 0; }
|