Skip to content

7-11 PAT 基础级排名

PAT 的段位分为 9 个级别,其中基础级考试分为青铜、白银、黄金、白金、钻石这 5 个段位,满分分别为 30、50、60、80、100。

基础级考试由报考单位订制需要的最高级别,设为级别 L,根据考生获得的分数所在的分数段决定该生获得的证书级别和证书内容,规则为:

  • 若考生的分数超过段位 L1 的满分,且不高于段位 L2 的满分,并且 L1 和 L2 为相邻段位,则该生获得 L2 段位的证书;
  • 证书上包含两个成绩:S/FR/T,其中 S 是本人得分;F 是该段位满分;R 是本人在该段位证书获得者中的排名;T 是位于该段位及以下段位考生总人数。

给定一组考生的成绩,请你编写程序生成他们的证书。

输入格式:

输入首先在第一行给出 2 个正整数:一个是不超过 1000 的正整数 N,为考生总人数;另一个是单位订制的最高段位级别 L,在 [1, 5] 区间内,依次对应青铜、白银、黄金、白金、钻石这 5 个段位。

随后 N 行,每行给出一位考生的准考证号和成绩,其间以空格分隔。准考证号为长度不超过 10 的、由数字和英文字母组成的字符串;成绩为不超过段位 L 的满分的非负整数。

输出格式:

按照成绩从高到低的顺序输出每位考生的证书信息,格式为:

准考证号 段位 S/F R/T
准考证号 段位 S/F R/T

成绩并列的考生拥有并列的排名,其后的考生名次按实际位次计算。例如有 5 位考生得到满分 100 时,他们都是第 1 名,而考 99 的考生就是第 6 名。成绩并列的考生按准考证号的字典序递增输出。题目保证准考证号没有重复。

注意:零分没有证书。对于零分的考生,只按字典序递增输出其准考证号。

输入样例:

tex
10 4
CN001 58
CN012 49
CN233 0
CN003 0
CN025 31
CN999 80
CN666 80
CN777 60
CN007 79
CN250 15
10 4
CN001 58
CN012 49
CN233 0
CN003 0
CN025 31
CN999 80
CN666 80
CN777 60
CN007 79
CN250 15

输出样例:

tex
CN666 4 80/80 1/10
CN999 4 80/80 1/10
CN007 4 79/80 3/10
CN777 3 60/60 1/7
CN001 3 58/60 2/7
CN012 2 49/50 1/5
CN025 2 31/50 2/5
CN250 1 15/30 1/3
CN003
CN233
CN666 4 80/80 1/10
CN999 4 80/80 1/10
CN007 4 79/80 3/10
CN777 3 60/60 1/7
CN001 3 58/60 2/7
CN012 2 49/50 1/5
CN025 2 31/50 2/5
CN250 1 15/30 1/3
CN003
CN233

Solution:

DANGER

测试点 1、4 答案错误

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int l = Integer.parseInt(input[1]);
        List<Rank> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            input = in.readLine().split(" ");
            int score = Integer.parseInt(input[1]);
            int L = 0;
            if (score <= 30) list.add(new Rank(input[0], 1, score, 30));
            else if (score <= 50) list.add(new Rank(input[0], 2, score, 50));
            else if (score <= 60) list.add(new Rank(input[0], 3, score, 60));
            else if (score <= 80) list.add(new Rank(input[0], 4, score, 80));
            else if (score <= 100) list.add(new Rank(input[0], 5, score, 100));
        }
        list.sort(null);
        int index = 1, cnt = 0, t = 0;
        Rank temp = list.get(0);
        StringBuilder sb = new StringBuilder();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            Rank rank = list.get(i);
            if (rank.score == 0) {
                sb.append(rank.num);
            } else {
                sb.append(rank.num).append(" ").append(rank.L).append(" ").append(rank.score).append("/")
                        .append(rank.fullScore).append(" ");
                if (temp.score == rank.score && temp.L == rank.L) {
                    sb.append(index).append("/").append(n);
                    t++;
                } else if (temp.score != rank.score && temp.L == rank.L) {
                    index = t + 1;
                    sb.append(index).append("/").append(n);
                    t++;
                } else {
                    temp = list.get(i);
                    index = 1;
                    n -= t;
                    sb.append(index).append("/").append(n);
                    t = 1;
                }
            }
            cnt++;
            if (i < size - 1) sb.append("\n");
        }
        System.out.println(sb);
    }
}


class Rank implements Comparable<Rank> {
    String num;
    int L;
    int score;
    int fullScore;

    public Rank(String num, int l, int score, int fullScore) {
        this.num = num;
        L = l;
        this.score = score;
        this.fullScore = fullScore;
    }

    @Override
    public int compareTo(Rank o) {
        int r = o.score - this.score;
        if (r == 0) r = this.num.compareTo(o.num);
        return r;
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int l = Integer.parseInt(input[1]);
        List<Rank> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            input = in.readLine().split(" ");
            int score = Integer.parseInt(input[1]);
            int L = 0;
            if (score <= 30) list.add(new Rank(input[0], 1, score, 30));
            else if (score <= 50) list.add(new Rank(input[0], 2, score, 50));
            else if (score <= 60) list.add(new Rank(input[0], 3, score, 60));
            else if (score <= 80) list.add(new Rank(input[0], 4, score, 80));
            else if (score <= 100) list.add(new Rank(input[0], 5, score, 100));
        }
        list.sort(null);
        int index = 1, cnt = 0, t = 0;
        Rank temp = list.get(0);
        StringBuilder sb = new StringBuilder();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            Rank rank = list.get(i);
            if (rank.score == 0) {
                sb.append(rank.num);
            } else {
                sb.append(rank.num).append(" ").append(rank.L).append(" ").append(rank.score).append("/")
                        .append(rank.fullScore).append(" ");
                if (temp.score == rank.score && temp.L == rank.L) {
                    sb.append(index).append("/").append(n);
                    t++;
                } else if (temp.score != rank.score && temp.L == rank.L) {
                    index = t + 1;
                    sb.append(index).append("/").append(n);
                    t++;
                } else {
                    temp = list.get(i);
                    index = 1;
                    n -= t;
                    sb.append(index).append("/").append(n);
                    t = 1;
                }
            }
            cnt++;
            if (i < size - 1) sb.append("\n");
        }
        System.out.println(sb);
    }
}


class Rank implements Comparable<Rank> {
    String num;
    int L;
    int score;
    int fullScore;

    public Rank(String num, int l, int score, int fullScore) {
        this.num = num;
        L = l;
        this.score = score;
        this.fullScore = fullScore;
    }

    @Override
    public int compareTo(Rank o) {
        int r = o.score - this.score;
        if (r == 0) r = this.num.compareTo(o.num);
        return r;
    }
}

Released under the MIT License.