[백준] 11718번 - 그대로 출력하기 [Java][C++]
[백준] 11718번 - 그대로 출력하기 [Java][C++]
1. 문제 풀이
주어진 입력 그대로 출력하는 문제로 입력이 얼마나 주어지는지는 알 수 없다. EOF를 활용해서 읽을 수 없을 때까지 읽으며 출력하면 된다.
2. 코드
1. 구현 [Java]
BufferedReader 의 readLine 메서드는 EOF에서 null 을 반환함을 활용해서 입력을 받고 BufferedWriter 로 출력했다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String line;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
bw.flush();
}
}
2. 구현 [C++]
getline 함수로 줄 단위로 입력을 받아서 그대로 출력했다.
1
2
3
4
5
6
7
8
9
10
11
12
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string line;
while (getline(cin, line)) {
cout << line << '\n';
}
}
3. 풀이 정보
1. 구현 [Java]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| Java 11 | 104 ms | 14212 KB | 433 B |
2. 구현 [C++]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| C++ 17 | 0 ms | 2024 KB | 204 B |
This post is licensed under CC BY 4.0 by the author.