結果

問題 No.571 3人兄弟(その2)
ユーザー tenten
提出日時 2020-09-07 20:39:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 81,144 KB
実行使用メモリ 41,324 KB
最終ジャッジ日時 2024-11-29 11:17:53
合計ジャッジ時間 4,652 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	Person[] arr = new Person[3];
    	for (int i = 0; i < 3; i++) {
    	    arr[i] = new Person((char)(i + 'A'), sc.nextInt(), sc.nextInt());
    	}
    	Arrays.sort(arr);
    	StringBuilder sb = new StringBuilder();
    	for (Person p : arr) {
    	    sb.append(p.name).append("\n");
    	}
    	System.out.print(sb);
    }
    
    static class Person implements Comparable<Person> {
        char name;
        int height;
        int weight;
        
        public Person(char name, int height, int weight) {
            this.name = name;
            this.height = height;
            this.weight = weight;
        }
        
        public int compareTo(Person another) {
            if (height == another.height) {
                return weight - another.weight;
            } else {
                return another.height - height;
            }
        }
    }

}
0