challenge 条件を満たす行を取り除く

ファイルから1行ずつ読み込み、"#"で始まる行だけを取り除いてファイルに出力するコードを書いてください。

サンプル入力

hello!
# remove this
 # don't remove this
bye!
サンプル出力
hello!
 # don't remove this
bye!

Posted feedbacks - Lua

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function remove_comments(in_filename, out_filename)
  out_f = io.output(out_filename)
  for line in io.lines(in_filename) do
    if string.sub(line, 1, 1) ~= "#" then
      out_f:write(line, "\n")
    end
  end
  out_f:close()
end

remove_comments("10.input", "10.output")

Index

Feed

Other

Link

Pathtraq

loading...