結果
| 問題 |
No.423 ハムスター語初級(数詞)
|
| コンテスト | |
| ユーザー |
naotest2
|
| 提出日時 | 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.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
naotest2