結果

問題 No.423 ハムスター語初級(数詞)
ユーザー yagi2yagi2
提出日時 2017-04-16 23:49:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 76,356 KB
実行使用メモリ 55,948 KB
最終ジャッジ日時 2023-09-26 09:07:58
合計ジャッジ時間 4,227 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,712 KB
testcase_01 AC 125 ms
55,904 KB
testcase_02 AC 125 ms
55,568 KB
testcase_03 AC 127 ms
55,776 KB
testcase_04 AC 126 ms
55,712 KB
testcase_05 AC 125 ms
55,756 KB
testcase_06 AC 125 ms
55,660 KB
testcase_07 AC 125 ms
55,440 KB
testcase_08 AC 126 ms
55,948 KB
testcase_09 AC 124 ms
55,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder.No423;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(encodeHamu(decodeHamu(sc.next()) * 2));
    }

    private static int decodeHamu(String str) {
        str += "A";
        StringBuilder bin = new StringBuilder();

        for (int i = 0; i < str.length() - 1; i++) {
            if (str.charAt(i) == 'm' && str.charAt(i+1) == 'u') {
                bin.append('1');
            } else if (str.charAt(i) == 'm' && (str.charAt(i+1) == 'h' || str.charAt(i+1) == 'A')) {
                bin.append('0');
            }
        }

        return Integer.parseInt(bin.toString(), 2);
    }

    private static String encodeHamu(int num) {
        String bin = Integer.toBinaryString(num);

        StringBuilder hamuBin = new StringBuilder();
        for (int i = 0; i < bin.length(); i++) {
            if (bin.charAt(i) == '1') {
                hamuBin.append("hamu");
            } else if (bin.charAt(i) == '0') {
                hamuBin.append("ham");
            }
        }

        return hamuBin.toString();
    }
}
0