結果
問題 | No.423 ハムスター語初級(数詞) |
ユーザー |
![]() |
提出日時 | 2017-05-26 18:51:03 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 450 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-09-19 20:08:22 |
合計ジャッジ時間 | 1,390 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
Main.rb:15: warning: possibly useless use of * in void context Syntax OK
ソースコード
S=gets.chompS.gsub!(/hamu/, '1')S.gsub!(/ham/, '0')def to10(str)r = 0for i in 0..(str.length-1)r += (2 ** (str.length-1-i)) * str[i].to_iendreturn rendto10(S) * 2def to2(num)if num == 0return "0"ends = ""while num > 0if num % 2 == 1s += "1"elses += "0"endnum = num >> 1endreturn s.reverseendk = to2(to10(S) * 2)k.gsub!(/1/, 'hamu')k.gsub!(/0/, 'ham')puts k