저장을 습관화

프로그래머스 LV.0 문자열 돌리기 본문

코딩 테스트/프로그래머스 - 자바스크립트

프로그래머스 LV.0 문자열 돌리기

ctrs 2023. 9. 8. 22:59

프로그래머스 LV.0 문자열 돌리기

https://school.programmers.co.kr/learn/courses/30/lessons/181945

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

1. 문제 명

문자열 돌리기


2. 문제 설명

문자열 str이 주어집니다.

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

 

3. 제한 사항

1 ≤ str의 길이 ≤ 10


4. 예시

입력 #1

abcde

 

출력 #1

a
b
c
d
e

 

5. 기본 제공 코드

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];
});


6. 제출한 내 답

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 () {
  for (i = 0; i < input[0].length; i++) {
    console.log(input[0][i]);
  }
});

 

6-2. VSC에 작성한 내용

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];
  for (i = 0; i < input[0].length; i++) {
    console.log(input[0][i]);
  }
});


7. 특이사항

없음


8. 다른 사람이 작성한 답

8-1.

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(c => console.log(c))
});

 

8-2.

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];
    for(let i of str){
        console.log(i)
    }
});

 

8-3.

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].map(x=>console.log(x))
});