結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー ks2mks2m
提出日時 2021-11-05 21:33:33
言語 Java19
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 3,516 ms
コンパイル使用メモリ 74,080 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-08-06 09:21:14
合計ジャッジ時間 7,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,440 KB
testcase_01 AC 115 ms
55,292 KB
testcase_02 AC 117 ms
55,872 KB
testcase_03 AC 116 ms
56,260 KB
testcase_04 AC 117 ms
56,064 KB
testcase_05 AC 117 ms
55,748 KB
testcase_06 AC 116 ms
55,576 KB
testcase_07 AC 117 ms
55,768 KB
testcase_08 AC 122 ms
55,624 KB
testcase_09 AC 122 ms
55,588 KB
testcase_10 AC 121 ms
55,816 KB
testcase_11 AC 119 ms
55,892 KB
testcase_12 AC 125 ms
55,684 KB
testcase_13 AC 122 ms
56,260 KB
testcase_14 AC 115 ms
55,728 KB
testcase_15 AC 115 ms
56,424 KB
testcase_16 AC 123 ms
56,120 KB
testcase_17 AC 119 ms
56,020 KB
testcase_18 AC 117 ms
56,028 KB
testcase_19 AC 116 ms
55,908 KB
testcase_20 AC 116 ms
55,492 KB
testcase_21 AC 116 ms
55,832 KB
testcase_22 AC 117 ms
55,600 KB
testcase_23 AC 117 ms
56,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length; i++) {
			int a = Integer.parseInt(String.valueOf(s[i]), 16);
			sb.append(Integer.toBinaryString(a));
		}

		int[] cnt = new int[8];
		int start = sb.length() % 3;
		if (start != 0) {
			int a = Integer.parseInt(sb.substring(0, start), 2);
			cnt[a]++;
		}
		for (int i = start; i < sb.length(); i += 3) {
			int a = Integer.parseInt(sb.substring(i, i + 3), 2);
			cnt[a]++;
		}

		int max = 0;
		for (int i = 0; i < cnt.length; i++) {
			max = Math.max(max, cnt[i]);
		}

		StringBuilder sb2 = new StringBuilder();
		for (int i = 0; i < cnt.length; i++) {
			if (cnt[i] == max) {
				sb2.append(i).append(' ');
			}
		}
		sb2.deleteCharAt(sb2.length() - 1);
		System.out.println(sb2.toString());
	}
}
0