結果

問題 No.571 3人兄弟(その2)
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 22:49:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 76,900 KB
実行使用メモリ 56,236 KB
最終ジャッジ日時 2023-08-13 15:05:58
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,836 KB
testcase_01 AC 122 ms
55,712 KB
testcase_02 AC 124 ms
55,968 KB
testcase_03 AC 124 ms
56,168 KB
testcase_04 AC 122 ms
55,652 KB
testcase_05 AC 124 ms
55,656 KB
testcase_06 AC 122 ms
55,984 KB
testcase_07 AC 123 ms
56,084 KB
testcase_08 AC 124 ms
56,012 KB
testcase_09 AC 124 ms
55,772 KB
testcase_10 AC 125 ms
56,236 KB
testcase_11 AC 124 ms
55,480 KB
testcase_12 AC 123 ms
55,792 KB
testcase_13 AC 124 ms
56,028 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