题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805261493977088
写了半天发现map不可以排序,我真是B了狗了,柳是用了map进行简化,方法还是很好的
也不想再写了,就这样吧
代码
#include <iostream>#include <algorithm>#include <vector>#include <string>#include <map>using namespace std;struct node {string name;int gp, gm, gf, g;};bool cmp(node a, node b) {return a.g != b.g ? a.g > b.g : a.name < b.name;}map<string, int> idx;int main() {int p, m, n, score, cnt = 1;cin >> p >> m >> n;vector<node> v, ans;string s;for (int i = 0; i < p; i++) {cin >> s >> score;if (score >= 200) {v.push_back(node{s, score, -1, -1, 0});idx[s] = cnt++;}}for (int i = 0; i < m; i++) {cin >> s >> score;if (idx[s] != 0) v[idx[s] - 1].gm = score;}for (int i = 0; i < n; i++) {cin >> s >> score;if (idx[s] != 0) {int temp = idx[s] - 1;v[temp].gf = v[temp].g = score;if (v[temp].gm > v[temp].gf) v[temp].g = int(v[temp].gm * 0.4 + v[temp].gf * 0.6 + 0.5);}}for (int i = 0; i < v.size(); i++)if (v[i].g >= 60) ans.push_back(v[i]);sort(ans.begin(), ans.end(), cmp);for (int i = 0; i < ans.size(); i++)printf("%s %d %d %d %d\n", ans[i].name.c_str(), ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g);return 0;}
