题解 | #排名#

排名

https://www.nowcoder.com/practice/f7c80167c5b04fd2ac4b6d7080a73f01

#include <iostream>
#include "vector"
#include "queue"
using namespace std;
struct student {
    string num;
    int score;
    student(string s, int i) {
        num = s;
        score = i;
    }
    bool operator< (student B)const {
        if (score == B.score) return num > B.num;
        return score < B.score;
    }

};
int main() {
    int N, M, G;
    while (cin >> N >> M >> G) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        if (N == 0) break;
        priority_queue<student> myQueue;
        vector<int> score;
        score.push_back(0);
        while (M--) {
            int temp;
            cin >> temp;
            score.push_back(temp);
        }
        while (N--) {
            string num;
            cin >> num;
            int finishNum;
            cin >> finishNum;
            int sscore = 0;
            while (finishNum--) {
                int qn;
                cin >> qn;
                sscore += score[qn];
            }
            if (sscore >= G) myQueue.push(student(num, sscore));
        }
        if (myQueue.size() == 0) cout << 0 << endl;
        else {
            cout << myQueue.size() << endl;
            while (!myQueue.empty()) {
                cout << myQueue.top().num << ' ' << myQueue.top().score << endl;
                myQueue.pop();
            }
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-28 12:15
点赞 评论 收藏
分享
07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务