結果

問題 No.423 ハムスター語初級(数詞)
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-05-03 17:24:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 4,121 ms
コンパイル使用メモリ 74,588 KB
実行使用メモリ 34,348 KB
最終ジャッジ日時 2023-10-12 07:59:29
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
34,348 KB
testcase_01 AC 49 ms
33,892 KB
testcase_02 AC 49 ms
33,788 KB
testcase_03 AC 48 ms
33,860 KB
testcase_04 AC 49 ms
33,924 KB
testcase_05 AC 50 ms
33,828 KB
testcase_06 AC 50 ms
33,872 KB
testcase_07 AC 48 ms
33,772 KB
testcase_08 AC 49 ms
33,892 KB
testcase_09 AC 50 ms
33,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String N = reader.readLine();
        String binaryString = hamToBinary(N);
        int doubledNum = Integer.parseInt(binaryString, 2) * 2;
        System.out.println(binaryToHam(Integer.toBinaryString(doubledNum)));
    }

    private static String hamToBinary(String N) {
        N += "h";
        StringBuilder binaryString = new StringBuilder();
        for (int i = 1; i < N.length(); i++) {
            if (N.charAt(i) == 'h') {
                if (N.charAt(i - 1) == 'u') {
                    binaryString.append(1);
                } else if (N.charAt(i - 1) == 'm') {
                    binaryString.append(0);
                }
            }
        }
        return binaryString.toString();
    }

    private static String binaryToHam(String binaryString) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < binaryString.length(); i++) {
            if (binaryString.charAt(i) == '0') {
                builder.append("ham");
            } else {
                builder.append("hamu");
            }
        }
        return builder.toString();
    }
}
0