[Programmers] 181946번 - 문자열 붙여서 출력하기 [Java][C++]
[Programmers] 181946번 - 문자열 붙여서 출력하기 [Java][C++]
1. 아이디어
str1, str2를 이어 붙여 출력해주면 된다.
2. 복잡도
| 시간복잡도 | 공간복잡도 |
|---|---|
| $O(N)$ | $O(1)$ |
$N$ =
str1+str2총 길이
3. 코드
풀이 [Java][C++]
입력을 받은 후 공백을 제거하는 방식으로 해결했다.
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().replace(" ", ""));
}
}
각 문자열을 연속해서 출력하는 방식으로 해결했다.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
string s1, s2;
cin >> s1 >> s2;
cout << s1 << s2;
}
This post is licensed under CC BY 4.0 by the author.