문제 설명
두 개의 문자열 str1
, str2
가 공백으로 구분되어 입력으로 주어집니다.
입출력 예와 같이 str1
과 str2
을 이어서 출력하는 코드를 작성해 보세요.
제한사항
- 1 ≤
str1
,str2
의 길이 ≤ 10
입출력 예
입력 #1
apple pen
출력 #1
applepen
입력 #2
Hello World!
출력 #2
HelloWorld!
두 개의 문자열 str1
, str2
가 공백으로 구분되어 입력으로 주어집니다.
입출력 예와 같이 str1
과 str2
을 이어서 출력하는 코드를 작성해 보세요.
str1
, str2
의 길이 ≤ 10입력 #1
apple pen
출력 #1
applepen
입력 #2
Hello World!
출력 #2
HelloWorld!
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
});
split()
함수를 사용해서 공백을 기준으로 문자열을 나눠요.
입력 #1을 기준으로 input[0]
에는 apple
이, input[1]
에는 pen
이 들어가요.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
const [str1, str2] = input;
console.log(str1 + str2);
});
문자열을 더하면 문자열이 이어져요. applepen
이 출력돼요.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
const [str1, str2] = input;
console.log(str1 + str2);
});