結果

問題 No.564 背の順
ユーザー YamaKasaYamaKasa
提出日時 2018-05-07 00:45:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 58,084 KB
最終ジャッジ日時 2023-09-10 10:52:06
合計ジャッジ時間 5,022 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
55,920 KB
testcase_01 AC 141 ms
56,224 KB
testcase_02 AC 150 ms
58,084 KB
testcase_03 AC 143 ms
56,492 KB
testcase_04 AC 141 ms
56,120 KB
testcase_05 AC 151 ms
55,940 KB
testcase_06 AC 153 ms
55,904 KB
testcase_07 AC 144 ms
56,288 KB
testcase_08 AC 152 ms
55,860 KB
testcase_09 AC 144 ms
57,928 KB
testcase_10 AC 144 ms
56,024 KB
testcase_11 AC 143 ms
56,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int N = scan.nextInt();
		int []H = new int[N - 1];
		for(int i = 0; i < N - 1; i++) {
			H[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(H);
		for(int i = N - 2; i >= 0; i--){
			if(h >= H[i]) {
				String k = Integer.toString(N - i - 1);
				int ans = N - i - 1;
				int l = k.length();
				if(k.charAt(l - 1) == '1') {
					System.out.println(ans + "st");
					break;
				}else if(k.charAt(l - 1) == '2') {
					System.out.println(ans + "nd");
					break;
				}else if(k.charAt(l - 1) == '3') {
					System.out.println(ans + "rd");
					break;
				}else {
					System.out.println(ans + "th");
					break;
				}
			}
		}
		if(h < H[0]) {
			System.out.println(N + "th");
		}
	}
}
0