Back on the Ladder - L2-027 Hall of Fame & Voucher (25 points)

Topic description

For students studying "Data Structures" in Chinese University MOOC (http://www.icourse163.org/ ), in order to get a certificate, the overall score must reach 60 points and above, and there are additional benefits: total Those who score in the [G, 100] range can get a 50 yuan PAT voucher; those who are in the [60, G) range can get a 20 yuan PAT voucher. It is common to national test centers and is valid for one year. At the same time, the teacher will also list the top K students in the overall evaluation into the "Hall of Fame" of the course. This question asks you to write a program to help teachers list Hall of Fame students and count how many PAT vouchers with a face value were issued in total.

Input format:

The input gives 3 integers in the first line, which are N (a positive integer not exceeding 10 000, which is the total number of students), G (an integer in the interval of (60,100), which is the dividing line of the voucher grade described in the title. ), K (a positive integer not exceeding 100 and not exceeding N, the lowest ranking for entering the Hall of Fame). Next N lines, each line gives a student's account number (a string of no more than 15 characters without spaces) and the overall grade (integer in the range [0, 100]), separated by spaces. The title guarantees that there are no duplicate accounts.

Output format:

First output the total face value of the issued PAT vouchers in one line. Then output the rank, account number, and grade of the students who entered the Hall of Fame in non-ascending order of overall evaluation scores, separated by 1 space. It should be noted that students with the same grades enjoy a tie ranking. When the ranking is tied, the output will be in ascending alphabetical order of the account number.

Input sample:

10 80 5
[email protected] 78
[email protected] 87
[email protected] 65
[email protected] 96
[email protected] 39
[email protected] 87
[email protected] 80
[email protected] 88
[email protected] 80
[email protected] 70

Sample output:

360
1 [email protected] 96
2 [email protected] 88
3 [email protected] 87
3 [email protected] 87
5 [email protected] 80
5 [email protected] 80

water problem

sort.
A difficulty may be how to accurately output the juxtaposition. If the score is the same as the previous one, let it have the same rank as the previous one; if it is different, the rank is equal to its sorted order

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 10010;
struct Node {
    
    
    string name;
    int score, rank;
    bool operator< (const Node& w) const {
    
    
        if (score == w.score) return name < w.name;
        return score > w.score;
    }
}node[N];
int n, g, k;
int calCoupon(int score) {
    
    
    if (score >= 60 && score < g) return 20;
    else if (score >= g && score <= 100) return 50;
    return 0;
}

int main() {
    
    
    cin >> n >> g >> k;
    
    int tot = 0;
    
    for (int i = 1; i <= n; i++) {
    
    
        string name;
        int score;
        cin >> name >> score;
        tot += calCoupon(score);
        node[i] = {
    
    name, score};
    }
    sort(node + 1, node + n + 1);
    node[1].rank = 1;
    for (int i = 2; i <= n; i++) {
    
    
        if (node[i].score == node[i-1].score) node[i].rank = node[i-1].rank;
        else node[i].rank = i;
    }
    
    cout << tot << endl;
    for (int i = 1; i <= n && node[i].rank <= k; i++) {
    
    
        cout << node[i].rank << ' ' << node[i].name << ' ' << node[i].score << endl;
    }
    
    return 0;
}

Back on the Ladder - L2-027 Hall of Fame & Voucher (25 points)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324147644&siteId=291194637