[JS] 백준 2675번 문자열반복

jsg_ko·2021년 11월 23일
0

코테연습

목록 보기
14/21
const fs = require("fs"); //파일받기위해 필요
const localFile = fs.existsSync("./input.txt"); // 내가 알고리즘 풀려는 폴더에 './input.txt'의 유무를 참,거짓으로 변수에 넣어라
const filePath = () => {
  // 참이면 내 input파일을 열고 그외는 백준의 알고리즘에서 주는 입력값을 받겠다.
  if (localFile) {
    return "./input.txt";
  }
  return "/dev/stdin";
};


const input = fs.readFileSync(filePath()).toString().trim().split("\n")



for (let i = 1; i < input.length; i++){
  const loopWord = Number(input[i][0]); // 주어진 테스트케이스 반복횟수  
  const Word = input[i].slice(2); // 테스트케이스 반복횟수와 공백구분포함 맨앞 요소 2개 자른거 할당 
  let result = ''; 
  for(let j = 0; j < Word.length; j ++){  
    for(let k = 1; k <= loopWord; k ++){// 테스트케이스 반복횟수만큼 for문 돌리기
      result = result + Word[j]; // 결과값에 추가해주기
    }
  }
  console.log(result);
}
profile
디버깅에서 재미를 추구하면 안되는 걸까

0개의 댓글