//入力文字読み取り var inputall = require('fs').readFileSync('/dev/stdin', 'utf8'); while (inputall.indexOf("hamu", 0) != -1 && inputall.indexOf("ham", 0) != -1) { inputall = inputall.replace("hamu", 1); inputall = inputall.replace("ham", 0); } //数値化 var inputnumber = Number(inputall); //2進数を10進数へ変換 var inputnumber_ten = parseInt(inputnumber, 2); //10進数を2倍 var inputnumber_ten = inputnumber_ten * 2; //10進数を2進数へ var inputstr_binary = inputnumber_ten.toString(2) //ハム語へ変換 while (inputstr_binary.indexOf("1", 0) != -1) { inputstr_binary = inputstr_binary.replace("1", "hamu"); } while (inputstr_binary.indexOf("0", 0) != -1) { inputstr_binary = inputstr_binary.replace(0, "ham"); } console.log(inputstr_binary)