작성일 :

문제 링크

11718번 - 그대로 출력하기

설명

여러 줄에 걸쳐 입력된 문자열을 그대로 출력하는 단순 입출력 문제입니다.

  • 입력은 여러 줄로 주어지며, 빈 줄도 포함될 수 있습니다.
  • 입력이 끝날 때까지 받은 문자열을 줄 단위로 그대로 출력해야 합니다.
  • 종료 조건은 EOF(End Of File)입니다.

접근법

  • 표준 입력을 줄 단위로 계속 받아 출력합니다.


C#에서는 Console.ReadLine()null을 반환하는 시점을 EOF로 판단합니다.

C++에서는 getline()으로 입력받고 cin.eof()로 종료를 감지합니다.


Code

[ C# ]

1
2
3
4
5
6
7
8
9
using System;

class Program {
  static void Main() {
    string? line;
    while ((line = Console.ReadLine()) != null)
      Console.WriteLine(line);
  }
}



[ C++ ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  while (true) {
    string str; getline(cin, str);
    cout << str;
    if (!cin.eof()) cout << "\n";
    else break;
  }

  return 0;
}