What Is Your Grade? HDU Java实现

解题思路
这道题有一个注意事项

*(you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems).

意思是:例:这个答对4个问题的学生必须是占全部答对4个问题的学生的一半及一半以上,才是95,其他都是90分*

1.创建两个数组,一个记录解决了(1,2,3,4)个问题的学生个数;一个为后期便于计算这个同学是得(95或者90)分;
2.创建一个学生类:定义成员变量:
id(记录该学生是输入的第几个学生)
score(记录该学生的的分数)
time(记录该学生所用的时间)
solved(记录该学生解决问题个数)
3.创建一个ArrayList集合,保存各个学生
4.创建一个数组,用于按照学生id输出学生成绩

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    static String begin = "00:00:00";
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        while(!sc.hasNext("-1")){
            int menber = sc.nextInt();
            int[] total = {0,0,0,0};
            int[] count = {0,0,0,0};
            List<student> ans = new ArrayList<>(menber);
            int[] resultArr = new int[menber];
            for(int i = 0; i < menber; i++){
                student stu = new student();
                stu.id = i;
                stu.solved = sc.nextInt();
                stu.time = GetTime(sc.next());
                if(stu.solved < 5 && stu.solved > 0){
                    total[stu.solved-1]++;
                }
                ans.add(stu);
            }
            ans.sort(new compareStu());
            Iterator<student> it = ans.iterator();
            while(it.hasNext()){
                student temp = it.next();
                switch (temp.solved){
                    case 0:
                        temp.score = 50;
                        break;
                    case 1:
                        count[0]++;
                        if(count[0] <= total[0] / 2){
                            temp.score = 65;
                        }else{
                            temp.score = 60;
                        }
                        break;
                    case 2:
                        count[1]++;
                        if(count[1] <= total[1] / 2){
                            temp.score = 75;
                        }else{
                            temp.score = 70;
                        }
                        break;
                    case 3:
                        count[2]++;
                        if(count[2] <= total[2] / 2){
                            temp.score = 85;
                        }else{
                            temp.score = 80;
                        }
                        break;
                    case 4:
                        count[3]++;
                        if(count[3] <= total[3] / 2){
                            temp.score = 95;
                        }else{
                            temp.score = 90;
                        }
                        break;
                    case 5:
                        temp.score = 100;
                        break;
                }
                resultArr[temp.id] = temp.score;
            }
            for(int score : resultArr){
                System.out.println(score);
            }
            System.out.println();
        }
    }

    private static long GetTime(String next) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        long MyTime = sdf.parse(begin).getTime() - sdf.parse(next).getTime();
        return MyTime;
    }

    static class student{
        int id;
        int solved;
        long time;
        int score;
    }

    static class compareStu implements Comparator<student>{
        int result;
        @Override
        public int compare(student o1, student o2) {
            result = Integer.compare(o2.solved, o1.solved);
            if(result == 0)
                result = Long.compare(o2.time,o1.time);

            return result;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值