結果

問題 No.423 ハムスター語初級(数詞)
ユーザー naotest2naotest2
提出日時 2017-05-26 18:51:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 11,972 KB
実行使用メモリ 16,104 KB
最終ジャッジ日時 2023-10-20 00:15:04
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,104 KB
testcase_01 AC 88 ms
16,104 KB
testcase_02 AC 89 ms
16,104 KB
testcase_03 AC 88 ms
16,104 KB
testcase_04 AC 90 ms
16,104 KB
testcase_05 AC 87 ms
16,104 KB
testcase_06 AC 86 ms
16,104 KB
testcase_07 AC 87 ms
16,104 KB
testcase_08 AC 87 ms
16,104 KB
testcase_09 AC 89 ms
16,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:15: warning: possibly useless use of * in void context
Syntax OK

ソースコード

diff #

S=gets.chomp

S.gsub!(/hamu/, '1')
S.gsub!(/ham/, '0')


def to10(str)
  r = 0
  for i in 0..(str.length-1)
    r += (2 ** (str.length-1-i)) * str[i].to_i
  end
  return r
end

to10(S) * 2

def to2(num)
  if num == 0
    return "0"
  end
  s = ""
  while num > 0
    if num % 2 == 1
      s += "1"
    else
      s += "0"
    end
    num = num >> 1
  end
  return s.reverse
end

k = to2(to10(S) * 2)

k.gsub!(/1/, 'hamu')
k.gsub!(/0/, 'ham')

puts k
0