► JS Algorithm/Programmers
[Programmers] JavaScript 알고리즘 | Lv.0 문자열 출력하기
다람트리
2024. 9. 9. 23:01
반응형
🔒 문제 설명
문자열 str이 주어질 때, str을 출력하는 코드를 작성해 보세요.
🔒 제한사항
- 1 ≤ str의 길이 ≤ 1,000,000
- str에는 공백이 없으며, 첫째 줄에 한 줄로만 주어집니다.
🔒 입출력 예
입력 #1
HelloWorld! |
출력 #1
HelloWorld! |
🔐 solution of mine
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
input = [line];
rl.close();
}).on("close", function () {
str = input[0];
console.log(str);
});
🔐 solution of others
switch
const readline = require("readline");
const rl = readline
.createInterface({
input: process.stdin,
output: process.stdout,
})
.on("line", console.log);
🔐 solution of others
Array.prototype.push()
Array.prototype.join()
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
input.push(line);
}).on("close", function () {
const str = input.join(" ");
console.log(str);
});
반응형