結果

問題 No.423 ハムスター語初級(数詞)
ユーザー yagi2yagi2
提出日時 2017-04-16 23:40:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 80,388 KB
実行使用メモリ 56,148 KB
最終ジャッジ日時 2023-09-26 09:07:53
合計ジャッジ時間 4,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,728 KB
testcase_01 AC 124 ms
56,032 KB
testcase_02 AC 123 ms
55,720 KB
testcase_03 WA -
testcase_04 AC 125 ms
55,704 KB
testcase_05 RE -
testcase_06 AC 123 ms
56,148 KB
testcase_07 WA -
testcase_08 AC 125 ms
55,444 KB
testcase_09 AC 124 ms
55,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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') {
                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