結果

問題 No.571 3人兄弟(その2)
ユーザー Pump0129Pump0129
提出日時 2018-03-26 20:33:21
言語 Java19
(openjdk 21)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,506 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 85,188 KB
実行使用メモリ 56,308 KB
最終ジャッジ日時 2023-09-07 13:17:03
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
55,796 KB
testcase_01 AC 107 ms
55,792 KB
testcase_02 AC 107 ms
55,920 KB
testcase_03 AC 109 ms
56,308 KB
testcase_04 AC 110 ms
56,160 KB
testcase_05 AC 113 ms
56,264 KB
testcase_06 AC 111 ms
55,672 KB
testcase_07 AC 110 ms
55,756 KB
testcase_08 AC 110 ms
55,916 KB
testcase_09 AC 109 ms
55,840 KB
testcase_10 AC 107 ms
55,820 KB
testcase_11 AC 110 ms
55,576 KB
testcase_12 AC 112 ms
56,268 KB
testcase_13 AC 108 ms
55,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no571;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        List<Human> humanList = new ArrayList<>();
        final String[] names = new String[] {"A", "B", "C"};

        for (int i = 0; i < 3; i++) {
            String[] datas = scan.nextLine().split(" ");

            humanList.add(new Human(names[i], Integer.parseInt(datas[0]), Integer.parseInt(datas[1])));
        }

        Collections.sort(humanList, new HumanComparator());

        humanList.stream().forEach(i -> System.out.println(i.getName()));
    }
}

class Human {
    private String name;
    private int height;
    private int weight;

    public Human(String name, int height, int weight) {
        this.name = name;
        this.height = height;
        this.weight = weight;
    }

    public String getName() { return name; }

    public int getHeight() { return height; }

    public int getWeight() { return weight; }
}

class HumanComparator implements Comparator<Human> {
    @Override
    public int compare(Human o1, Human o2) {
        if (o1.getHeight() < o2.getHeight()) {
            return 1;
        } else if(o1.getHeight() == o2.getHeight()) {
            if (o2.getWeight() < o1.getWeight()) {
                return 1;
            }else {
                return -1;
            }
        } else {
            return -1;
        }
    }
}
0