結果

問題 No.564 背の順
ユーザー tentententen
提出日時 2020-12-09 14:25:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 75,120 KB
実行使用メモリ 57,728 KB
最終ジャッジ日時 2023-10-19 04:51:59
合計ジャッジ時間 4,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
55,628 KB
testcase_01 AC 139 ms
57,404 KB
testcase_02 AC 149 ms
57,724 KB
testcase_03 AC 141 ms
57,588 KB
testcase_04 AC 140 ms
57,488 KB
testcase_05 AC 149 ms
57,728 KB
testcase_06 AC 150 ms
57,692 KB
testcase_07 AC 144 ms
57,424 KB
testcase_08 AC 148 ms
57,712 KB
testcase_09 AC 139 ms
57,516 KB
testcase_10 AC 138 ms
57,480 KB
testcase_11 AC 141 ms
57,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[n];
        arr[0] = h;
        for (int i = 1; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (arr[n - i] == h) {
                ans = i;
                break;
            }
        }
        System.out.print(ans);
        if (ans % 10 == 1) {
            System.out.println("st");
        } else if (ans % 10 == 2) {
            System.out.println("nd");
        } else if (ans % 10 == 3) {
            System.out.println("rd");
        } else {
            System.out.println("th");
        }
    }
}
0