1015 德才论 (25分) -java

/**
 * @author :zxq
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static class Stu {
        String id;
        int de;
        int cai;
        int sum;

        public Stu() {
        }

        @Override
        public String toString() {
            return id + " " + de + " " + cai;
        }
    }

    private static class StuComparetor implements Comparator<Stu> {
        @Override
        public int compare(Stu s1, Stu s2) {
            return s1.sum == s2.sum ? s2.de == s1.de ? s1.id.compareTo(s2.id) : s2.de - s1.de : s2.sum - s1.sum;
        }
    }

    public static void main(String[] args) throws Exception {
        /*
            1.考生类别:
            本题有4类考生,这些考生必须先满足
            d>=L&&c>=L
            然后每类考生要满足一定条件:
            第1类考生:d>=H&&c>=H
            第2类考生:注意题目所说的“德分到线”是指德分不小于线而不是等于线,所以条件为d>=H&&c<H
            第3类考生:d<H&&c<H&&d>=c
            第4类考生:除上述3类考生外的考生
            按总分降序,总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
         */
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] first = in.readLine().split(" ");
        int n = Integer.parseInt(first[0]);
        int l = Integer.parseInt(first[1]);
        int h = Integer.parseInt(first[2]);
        List<Stu> g1 = new ArrayList<>();
        List<Stu> g2 = new ArrayList<>();
        List<Stu> g3 = new ArrayList<>();
        List<Stu> g4 = new ArrayList<>();
        int cnt = 0;
        while (n-- > 0) {
            Stu stu = new Stu();
            String[] strings = in.readLine().split(" ");
            stu.id = strings[0];
            stu.de = Integer.parseInt(strings[1]);
            stu.cai = Integer.parseInt(strings[2]);
            stu.sum = stu.de + stu.cai;
            if (stu.de >= l && stu.cai >= l) {
                cnt++;
                if (stu.de >= h && stu.cai >= h) {
                    g1.add(stu);
                } else if (stu.de >= h ) {
                    g2.add(stu);
                } else if (stu.de > stu.cai) {
                    g3.add(stu);
                } else {
                    g4.add(stu);
                }
            }
        }
        g1.sort((s1, s2) -> s1.sum == s2.sum ? s2.de == s1.de ? s1.id.compareTo(s2.id) : s2.de - s1.de : s2.sum - s1.sum);
        g2.sort(new StuComparetor());
        g3.sort(new StuComparetor());
        g4.sort(new StuComparetor());

        System.out.println(cnt);
        g1.forEach(System.out::println);
        g2.forEach(System.out::println);
        g3.forEach(System.out::println);
        g4.forEach(System.out::println);
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容