문자열 돌리기

도비김·2024년 2월 22일
0
문제 설명

문자열 str이 주어집니다.
문자열을 시계방향으로 90도 돌려서 아래 입출력 예와 같이 출력하는 코드를 작성해 보세요.


제한사항

1 ≤ str의 길이 ≤ 10


입출력 예

입력 #1

abcde

출력 #1

a
b
c
d
e

solution

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = [line];
}).on('close',function(){
    str = input[0];
    [...str].forEach(a => console.log(a));
});

입력값 그대로 forEach를 사용해 바로 출력한다.

다른 풀이

for(let i of str){console.log(i)}

for(let i = 0 ; i < str.length; i++)console.log(str[i])

[...str].map(x=>console.log(x))
profile
To Infinity, and Beyond!

0개의 댓글