写了很久这题,一直没看到时总分的排名,提交一直错误,读了好几遍题目才看到
#include"iostream" #include "string" #include "algorithm" using namespace std; struct stu { int score; string name; }; bool cmp(stu A, stu B) { return A.score>B.score; } int main() { int n, m; string a[100]; cin >> n; struct stu s[100]; struct stu t[100]; for (int i = 0; i<n; i++) cin >> a[i]; cin >> m; int s1; for (int i = 0; i<m; i++) { for (int j = 0; j<n; j++) { cin >> s[j].score >> s[j].name; } if (i == 0) { for (int j = 0; j < n; j++) { t[j].score = s[j].score; t[j].name = s[j].name; } } else { for (int j = 0; j < n; j++) { for (int o = 0; o < n; o++) { if (s[o].name == t[j].name) { t[j].score = t[j].score + s[o].score; } } } } sort(t, t + n, cmp); int p; for (int j = 0; j<n; j++) { if (t[j].name == a[0]) { s1 = t[j].score; p = j; break; } } for (int j = 0; j<n; j++) { if (t[j].score <= s1) { cout << j + 1 << endl; break; } } } return 0; }
0.0分
0 人评分
C语言训练-字符串正反连接 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:761 |
A+B for Input-Output Practice (III) (C语言代码)浏览:592 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:614 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1482 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:866 |
1071题解浏览:584 |
简单的a+b (C语言代码)浏览:572 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:1108 |
神奇的fans (C语言代码)浏览:1124 |