HDOJ 2093 考试排名

239 篇文章 0 订阅

HDACM 2093

练耐心

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        List<Student2> list = new ArrayList<Student2>();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        while (sc.hasNext()) {
            Student2 s = new Student2();
            s.name = sc.next();
            s.score = new String[n];
            for (int i = 0; i < s.score.length; i++) {
                s.score[i] = sc.next();
            }
            list.add(s);
        }
        Student2[] students = new Student2[list.size()]; 
        for (int i = 0; i < list.size(); i++) {
            int count = 0;
            int time = 0;
            for (int j = 0; j < list.get(i).score.length; j++) {
                String score = list.get(i).score[j];
                char c = score.charAt(0);
                if (c!='-'&&c!='0') {
                    count++;
                }
                if (c=='-'||c=='0') {
                    continue;
                }
                String a="";
                String b="";
                boolean boo = true;
                for (int k = 0; k < score.length(); k++) {
                    c = score.charAt(k);
                    if (c>='0'&&c<='9') {
                        if (boo) {
                            a = a+c;
                        }else{
                            b = b+c;
                        }
                    }else{
                        boo = false;
                    }
                }
                if (!"".equals(a)) {
                    time += Integer.parseInt(a);
                }
                if (!"".equals(b)) {
                    time += m*Integer.parseInt(b);
                }
            }
            students[i] = list.get(i);
            students[i].count = count;
            students[i].time = time;
        }
        Arrays.sort(students,new Comparator<Student2>() {
            @Override
            public int compare(Student2 o1, Student2 o2) {
                if (o1.count>o2.count) {
                    return -1;
                }
                if (o1.count<o2.count) {
                    return 1;
                }
                if (o1.count==o2.count) {
                    if (o1.time>o2.time) {
                        return 1;
                    }
                    if (o1.time<o2.time) {
                        return -1;
                    }
                    if (o1.time == o2.time) {
                        if (o1.name.compareTo(o2.name)>0) {
                            return 1;
                        }
                        if (o1.name.compareTo(o2.name)<0) {
                            return -1;
                        }
                    }
                }
                return 0;
            }
        });
        for (int i = 0; i < students.length; i++) {
            System.out.printf("%-10s %2d %4d",students[i].name,students[i].count,students[i].time);
            System.out.println();
        }
        sc.close();
    }
}
class Student2{
    String name;
    String[] score;
    int count;
    int time;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值