結果

問題 No.571 3人兄弟(その2)
ユーザー kohaku_kohaku
提出日時 2019-02-21 22:49:43
言語 Java
(openjdk 23)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 79,380 KB
実行使用メモリ 54,360 KB
最終ジャッジ日時 2024-11-21 10:49:47
合計ジャッジ時間 4,964 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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