結果

問題 No.423 ハムスター語初級(数詞)
ユーザー nullzinenullzine
提出日時 2017-01-19 20:59:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 3,028 ms
コンパイル使用メモリ 87,444 KB
実行使用メモリ 58,652 KB
最終ジャッジ日時 2023-08-24 17:15:28
合計ジャッジ時間 4,545 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
56,856 KB
testcase_01 AC 161 ms
56,756 KB
testcase_02 AC 157 ms
57,272 KB
testcase_03 AC 154 ms
56,560 KB
testcase_04 AC 153 ms
56,572 KB
testcase_05 AC 120 ms
55,776 KB
testcase_06 AC 155 ms
56,744 KB
testcase_07 AC 155 ms
56,744 KB
testcase_08 AC 155 ms
56,840 KB
testcase_09 AC 154 ms
58,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * Created by nullzine on 2017/01/18.
 */
public class Main {

    public static void main(String[] args){
        new Main().run();
    }

    private void run(){
        System.out.println(bin2Ham(dec2Bin(bin2Dec(ham2Bin(new java.util.Scanner(System.in).nextLine()))*2)));
    }

    private int bin2Dec(String str){
        int ret=0;
        for(int i=0;i<str.length();i++){
            ret+=Integer.parseInt(str.charAt(str.length()-1-i)+"")*Math.pow(2, i);
        }
        return ret;
    }

    private String dec2Bin(int n){
        if(n==0){
            return "0";
        }
        String str="";
        while(n!=0){
            str=(n%2)+str;
            n/=2;
        }
        return str;
    }

    private String bin2Ham(String bin){
        return bin.replaceAll("0","ham").replaceAll("1","hamu");
    }

    private String ham2Bin(String ham){
        return ham.replaceAll("hamu","1").replaceAll("ham","0");
    }

}
0