結果

問題 No.423 ハムスター語初級(数詞)
ユーザー nullzine
提出日時 2017-01-19 20:59:38
言語 Java
(openjdk 23)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 2,833 ms
コンパイル使用メモリ 76,720 KB
実行使用メモリ 47,204 KB
最終ジャッジ日時 2024-12-23 01:32:11
合計ジャッジ時間 4,828 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

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