結果

問題 No.571 3人兄弟(その2)
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 22:49:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 79,812 KB
実行使用メモリ 54,320 KB
最終ジャッジ日時 2024-05-01 07:57:55
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
53,840 KB
testcase_01 AC 122 ms
54,016 KB
testcase_02 AC 112 ms
53,160 KB
testcase_03 AC 120 ms
54,064 KB
testcase_04 AC 122 ms
54,320 KB
testcase_05 AC 102 ms
52,968 KB
testcase_06 AC 108 ms
53,844 KB
testcase_07 AC 110 ms
54,192 KB
testcase_08 AC 113 ms
54,136 KB
testcase_09 AC 102 ms
52,572 KB
testcase_10 AC 115 ms
53,952 KB
testcase_11 AC 114 ms
53,900 KB
testcase_12 AC 104 ms
52,604 KB
testcase_13 AC 103 ms
52,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	static public void main(String[]args) throws Exception {
		Scanner sc = new Scanner(System.in);
		final int NUM = 3;
		List<Person> list = new ArrayList<>();

		for(int i=0; i < NUM; i++) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			char c = (char) ('A' + i);
			String name = String.valueOf(c);
			list.add(new Person(name, h, w));
		}
		Collections.sort(list, new PersonComparator());
		for(int i=0; i < NUM; i++) {
			System.out.println(list.get(i).getName());
		}
	}
}

class Person {
	private String name;
	private int heigth;
	private int weight;

	private Person() {

	}

	public Person(String name, int heigth, int weight) {
		this.name = name;
		this.heigth = heigth;
		this.weight = weight;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getHeigth() {
		return heigth;
	}

	public void setHeigth(int heigth) {
		this.heigth = heigth;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
}

class PersonComparator implements Comparator<Person> {

	@Override
	public int compare(Person p1, Person p2) {
		int dh = p1.getHeigth() - p2.getHeigth();
		if(dh != 0) {
			return -dh;
		} else {
			int dw = p1.getWeight() - p2.getWeight();
			return dw;
		}
	}

}
0