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 44 45 46
| #include <vector> #include <string> #include <map> #大专栏 PAT B1080 MOOC期终成绩(C++)ta-keyword">include <iostream> #include <algorithm> using namespace std; struct { string name; int gp = 0, gm = -1, gf = 0, g = 0; }newstu; vector<Student> stu, ans; map<string, int> nametoi; bool cmp(Student a, Student b){ if(a.g == b.g) return a.name < b.name; else return a.g > b.g; } int main() { int n1, n2, n3; cin >> n1 >> n2 >> n3; string id; int score, i, cnt = 0; for(i = 0; i < n1 + n2 + n3; i++){ cin >> id >> score; if(nametoi.find(id) == nametoi.end()){ newstu.name = id; stu.push_back(newstu); nametoi[id] = cnt++; } if(i < n1) stu[nametoi[id]].gp += score; else if(i < n1 + n2) stu[nametoi[id]].gm = score; else stu[nametoi[id]].gf = score; } for(int i = 0; i < cnt; i++){ if(stu[i].gp >= 200){ stu[i].g = (stu[i].gm > stu[i].gf) ? (int)((stu[i].gm * 4 + stu[i].gf * 6 + 5)/10) : stu[i].gf; if(stu[i].g >= 60) ans.push_back(stu[i]); } } sort(ans.begin(), ans.begin() + ans.size(), cmp); for(int i = 0; i < ans.size(); i++){ cout << ans[i].name; printf(" %d %d %d %dn", ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g); } return 0; }
|