Post

[BaekJoon] #11365 - !밀비 급일 [Java][C++]

[BaekJoon] #11365 - !밀비 급일 [Java][C++]

문제 링크


1. 아이디어

"END"가 나오기 전까지 주어진 각 라인을 뒤집어서 출력만 하면 된다. 내장 함수를 활용하면 간단하게 해결할 수 있다.


2. 복잡도

접근시간공간
풀이$O(N)$$O(1)$

($N$ = 모든 줄의 길이의 총합)


3. 코드

풀이 [Java][C++]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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));

        while (true) {
            String line = br.readLine();
            if (line.equals("END")) break;

            bw.write(new StringBuilder(line).reverse().toString());
            bw.newLine();
        }

        bw.flush();
    }
}
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(0);
    cin.tie(0);

    while (true) {
        string line;
        getline(cin, line);

        if (line == "END") break;

        reverse(line.begin(), line.end());
        cout << line << '\n';
    }
}

This post is licensed under CC BY 4.0 by the author.