Post

[Programmers] #181952 - 문자열 출력하기 [Java][C++][Python]

공백 없는 문자열을 입력받아 그대로 출력하는 워밍업 문제.

[Programmers] #181952 - 문자열 출력하기 [Java][C++][Python]

문제 링크


1. 아이디어

표준입력으로 주어지는 문자열 str을 그대로 출력하면 되는 문제다.


2. 복잡도

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

($N$ = 문자열 길이)


3. 코드

풀이 [Java][C++][Python]

문자열에 공백이 포함되지 않는다는 제약 덕분에, 한 줄 전체를 읽는 방식과 공백 단위로 끊어 읽는 방식 둘 다 결과가 같다.

1
2
3
4
5
6
7
8
import java.io.*;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(br.readLine());
    }
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

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

    string s;
    cin >> s;
    cout << s;
}
1
2
3
4
5
import sys

input = sys.stdin.readline

print(input())

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