ファイルへの追加
ファイルを扱う際にサポートされているいくつかのモードを思い出しましょう:
モード | 操作 | 例 |
---|---|---|
| 読み込み(デフォルト) |
|
| 書き込み |
|
| 追加 |
|
| 読み書き |
|
| 新規作成(存在する場合はエラー) |
|
コンピューターにはさまざまなファイルが存在します。あなたはそれらにいくつかの行を追加するよう求められています。
入力は2行からなります。最初の行はファイル名です。2番目の行はそのファイルに追加したい内容です。
プログラムは、まず指定された行をファイルに追加し、その後ファイルの全内容を出力する必要があります。
入力 | doc.txt(初期内容) | 出力 | doc.txt(結果の内容) |
---|---|---|---|
doc.txt This is the second line | This is the first line | This is the first line This is the second line | This is the first line This is the second line |
入力 | empty.txt(初期内容) | 出力 | empty.txt(結果の内容) |
---|---|---|---|
empty.txt Adding some content | Adding some content | Adding some content |
入力 | multiline.txt(初期内容) | 出力 | multiline.txt(結果の内容) |
---|---|---|---|
multiline.txt The final line! | This is some very very long document with many lines of text… | This is some very very long document with many lines of text… The final line! | This is some very very long document with many lines of text… The final line! |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB