長さが奇数の場合、つまりinput = "102" first_half = "1" second_half = "2"の場合、ルビーが中央の数字を無視して、数字の文字列の前半と後半を見つけようとしています。
このコードを使用する
i = gets
first_half=i[0..(i.length / 2 - 1).floor]
second_half = i[i.length -first_half.length)..i.length - 1]
print "#{first_half}\n#{second_half}"
ただし、この入力の場合、出力は10( "\ n")2です。
ただし、コードはirbでは正しく機能します。誰かが私が抱えている問題が何であるかを見ることができますか?