ZZULIOJ 1197: 考试排名(一)(结构体专题),Java

ZZULIOJ 1197: 考试排名(一)(结构体专题),Java

题目描述

今天浙大研究生复试的上机考试跟传统笔试的打分规则相似,总共有n道题,每道题有对应分值,最后计算总成绩。现给定录取分数线,请你写程序找出最后通过分数线的考生,并将他们的成绩按降序打印。

输入

第1行给出考生人数N ( 1<= N<=100 )、考题数M (1<=M<=10 )、分数线(正整数)G;
第2行排序给出第1题至第M题的正整数分值;
以下N行,每行给出一名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。

输出

首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考号的升序输出。

样例输入 Copy
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
样例输出 Copy
3
CS003 60
CS001 37
CS004 37
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Student {
    String id;
    int totalScore;

    public Student(String id, int totalScore) {
        this.id = id;
        this.totalScore = totalScore;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // Number of students
        int m = sc.nextInt(); // Number of questions
        int g = sc.nextInt(); // Pass score

        int[] scores = new int[m];
        for (int i = 0; i < m; i++) {
            scores[i] = sc.nextInt();
        }

        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String id = sc.next();
            int solvedCount = sc.nextInt();
            int totalScore = 0;
            for (int j = 0; j < solvedCount; j++) {
                int questionIndex = sc.nextInt() - 1;
                totalScore += scores[questionIndex];
            }
            if (totalScore >= g) {
                students.add(new Student(id, totalScore));
            }
        }

        Collections.sort(students, (s1, s2) -> {
            if (s1.totalScore != s2.totalScore) {
                return Integer.compare(s2.totalScore, s1.totalScore);
            } else {
                return s1.id.compareTo(s2.id);
            }
        });

        System.out.println(students.size());
        for (Student student : students) {
            System.out.println(student.id + " " + student.totalScore);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wa_Automata

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值