結果

問題 No.564 背の順
ユーザー jimanojimano
提出日時 2018-01-24 21:08:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 3,448 ms
コンパイル使用メモリ 81,488 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-08-27 02:17:56
合計ジャッジ時間 6,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
56,132 KB
testcase_01 WA -
testcase_02 AC 148 ms
56,132 KB
testcase_03 WA -
testcase_04 AC 134 ms
55,992 KB
testcase_05 AC 144 ms
55,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 134 ms
55,604 KB
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package me.yukicoder.lv1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class No0564 {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int num = sc.nextInt();
			int cnt = 1;
			List<Integer> l = new ArrayList<>();
			l.add(h);

			for (int i = 1; i < num; i++) {
				l.add(sc.nextInt());
			}
			Collections.sort(l);
			Collections.reverse(l);
			for (int i : l) {
				if (i == h)
					break;
				cnt++;
			}

			// 一の位の判断
			String strNum = Integer.toString(cnt);
			if (strNum.lastIndexOf(1) == strNum.length() - 1) {
				System.out.println(cnt + "st");
			} else if (strNum.lastIndexOf(2) == strNum.length() - 1) {
				System.out.println(cnt + "nd");
			} else if (strNum.lastIndexOf(3) == strNum.length() - 1) {
				System.out.println(cnt + "rd");
			} else {
				System.out.println(cnt + "th");
			}
		}
	}
}
0