-
프로그래머스 | 문자열 반복해서 출력하기코딩/코딩테스트 2024. 2. 3. 23:16
문제 설명
문자열 str과 정수 n이 주어집니다.
str이 n번 반복된 문자열을 만들어 출력하는 코드를 작성해 보세요.
제한사항- 1 ≤ str의 길이 ≤ 10
- 1 ≤ n ≤ 5
입출력 예입력 #1
string 5
출력 #1
stringstringstringstringstring
💡나의 풀이
1. repeat 메서드를 활용해 string을 n만큼 반복함.
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 () { str = input[0]; n = Number(input[1]); console.log(str.repeat(n)) });
'코딩 > 코딩테스트' 카테고리의 다른 글
프로그래머스 | 특수문자 출력하기 (0) 2024.02.04 프로그래머스 | 대소문자 바꿔서 출력하기 JS (0) 2024.02.04 프로그래머스 | n의 배수 고르기 (1) 2024.02.03 프로그래머스 코딩테스트 | 나이 출력 (0) 2023.04.13 프로그래머스 코딩테스트 | 두 수의 나눗셈 (0) 2023.04.12