2
将文本从输入文件转换为莫尔斯码,然后将结果放入输出txt文件。文件本身正在创建,但没有输出。文件没有得到输出
MAXLINELENGTH = 40
codes = ['.-', '-...', '-.-.', '-..', '.', '..-.',
'--.', '....', '..', '.---', '-.-', '.-..',
'--', '-.', '---', '.--.', '--.-', '.-.',
'...', '-', '..-', '...-', '.--', '-..-',
'-.--', '--..','.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..',
'----.', '-----']
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
fin = File.open("input.txt", "r")
fout = File.open("output.txt", "w")
line_length = 0
while character = fin.getc
if index = chars.index(character.upcase)
morse = codes[index]
elsif character == " "
fout.print " "
line_length = line_length + 4
end
if line_length >= MAXLINELENGTH
fout.print "\n"
line_length = 0
end
end
fin.close
fout.close
:D没有注意到哈哈非常感谢 – RubyNovice
认为我已经很抱歉stackoverflow新手:P – RubyNovice