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

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

サンプル入力

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

Posted feedbacks - D

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
module doukaku;
private import std.stream;
void remove_comments(BufferedFile in_f, BufferedFile out_f) {
    foreach(char[] line; in_f) {
        if (line[0] != '#')
            out_f.writeLine(line);
    }
}

void main() {
    BufferedFile in_f = new BufferedFile("10.input", FileMode.In);
    BufferedFile out_f = new BufferedFile("10.output", FileMode.OutNew);
    remove_comments(in_f, out_f);
    in_f.close();
    out_f.close();
}

Index

Feed

Other

Link

Pathtraq

loading...