Post

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

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

문제 링크


1. 문제 풀이


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


2. 코드


1. 풀이 [Java]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 str = br.readLine();

            if (str.equals("END")) break;

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

        bw.flush();
    }
}


2. 풀이 [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 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.