7-9 期末编程作业计分规则

期末编程作业计分规则。

PTA上的题目集的排名页以总分(满分不一定是100分)的形式按排名顺序显示每个同学的成绩,但相同分数的同学无论排名是靠前还是最后得分都是一样的。为了表示排名区分度,根据排名给出了一个简单的计分规则,以示有所区分。计分规则如下:

成绩折合成100分(取整),然后将班级人数按输入的百分比分成四个个档(如前三档人数的百分比分别为10%、40%、40%,则输入10、40 、40,各档人数均向上取整,剩下的则为最后一档人数),给出一个减分序列,每档所要减去的分数为减分序列中对应的位置及之前的值的总和。

如一个班级有10个同学,若得分都是100分,减分序列为1、3、2、2,若按10%、40%、40%的人数比例的排名分别减去1分、4分、6分、8分。这样每个同学最后的总分得分依次为:100、96、96、96、96、94、94、94、94、92。

要求编程实现根据上述计分规则计算后的成绩得分,按原排名先后输出每个同学的百分制最后得分。

输入格式:

输入四行,第一行输入班级人数和满分分数,第二行按排名顺序输入每个同学的分数,第三行输入各档分数的人数百分比(三项),第四行输入减分序列。

输出格式:

输出根据计分规则计算后的百分制得分,两个成绩之间以两个空格隔开

注意:最后一个数后面有两个空格

输入样例1:

在这里给出一组输入。例如:

10 100
100 100 100 100 100 100 100 100 100 100
10 40 40
1 3 2 2

输出样例1:

在这里给出相应的输出。例如:

99  96  96  96  96  94  94  94  94  92  

输入样例2:

在这里给出一组输入。例如:

7 120
110 95 95 92 92 92 88
10 20 40
0 1 1 1

输出样例2:

在这里给出相应的输出。例如:

91  78  78  74  74  74  70  
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 输入班级人数和满分分数
        int numStudents = scanner.nextInt();
        int fullScore = scanner.nextInt();

        // 输入每个同学的分数
        int[] scores = new int[numStudents];
        for (int i = 0; i < numStudents; i++) {
            scores[i] = scanner.nextInt();
        }

        // 输入各档分数的人数百分比
        int[] percentage = new int[3];
        for (int i = 0; i < 3; i++) {
            percentage[i] = scanner.nextInt();
        }

        // 输入减分序列
        int[] deduction = new int[4];
        for (int i = 0; i < 4; i++) {
            deduction[i] = scanner.nextInt();
        }

        // 计算每个同学的最终得分
        int[] finalScores = calculateFinalScores(numStudents, fullScore, scores, percentage, deduction);

        // 输出最终得分
        for (int i = 0; i < numStudents; i++) {
            System.out.print(finalScores[i] + "  ");
        }
        System.out.println();
    }

    // 计算每个同学的最终得分
    private static int[] calculateFinalScores(int numStudents, int fullScore, int[] scores, int[] percentage, int[] deduction) {
        int[] finalScores = new int[numStudents];

        // 将成绩折合成100分
        for (int i = 0; i < numStudents; i++) {
            finalScores[i] = (int) Math.round(((double) scores[i] / fullScore) * 100);
        }

        // 计算各档人数
        int[] tierSizes = calculateTierSizes(numStudents, percentage);

        // 计算每个同学的减分
        int currentDeduction = 0;
        int tierIndex = 0;
        int currentTierSize = tierSizes[tierIndex];
        for (int i = 0; i < numStudents; i++) {
            if (i < currentTierSize) {
                finalScores[i] -= currentDeduction;
            } else {
                tierIndex++;
                currentTierSize += tierSizes[tierIndex];
                currentDeduction += deduction[tierIndex];
                finalScores[i] -= currentDeduction;
            }
        }

        return finalScores;
    }

    // 计算各档人数
    private static int[] calculateTierSizes(int numStudents, int[] percentage) {
        int[] tierSizes = new int[4];
        int remainingStudents = numStudents;
        for (int i = 0; i < 3; i++) {
            tierSizes[i] = (int) Math.ceil(((double) percentage[i] / 100) * numStudents);
            remainingStudents -= tierSizes[i];
        }
        tierSizes[3] = remainingStudents;
        return tierSizes;
    }
}

 

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值