题解 | #排名#
排名
https://www.nowcoder.com/practice/f7c80167c5b04fd2ac4b6d7080a73f01
#include <iostream> #include <algorithm> #include <string> using namespace std; const int MAXN = 10 + 10; const int MAXM = 1000 + 10; int arr[MAXN];//题目 struct Student { string id; int score; }; Student student[MAXM]; bool Compare (Student x, Student y){ if (x.score != y.score){ return x.score > y.score; }else{ return x.id < y.id; } return false; } int main(){ int n, m, g; while(cin >> n){ if (n == 0){ break; } cin >> m >> g; for (int i = 1; i <= m; i++){ cin >> arr[i]; } for (int i = 0; i < n; i++){ int tihao, finishNum; int sum = 0; cin >> student[i].id >> finishNum; for (int j = 1; j <= finishNum; j++){ cin >> tihao; sum += arr[tihao]; } student[i].score = sum; } sort(student, student + n, Compare); int k = 0; for (int i = 0; i < n; i++){ if (student[i].score >= g){ k++; }else{ break; } } cout << k << endl; for (int i = 0; i < k; i++){ cout << student[i].id << " " << student[i].score << endl; } } return 0; }