언젠가는 펼쳐 볼 아카이브

[BOJ] 2444번 - 별찍기 - 7 본문

IT/Baekjoon Oline Judge

[BOJ] 2444번 - 별찍기 - 7

개발자희망생고롸파덕 2023. 8. 22. 16:01

사용언어: javascript - node.js

 

#제출코드

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs.readFileSync(filePath).toString().trim();

solution(+input);

function solution(input) {
  // 정방향
  for (let i = 0; i < input - 1; i++) {
    let star = '*'.repeat(2 * i + 1);
    let space = ' '.repeat(input - i);

    console.log(space + star);
  }

  //역방향
  for (let i = input - 1; i >= 0; i--) {
    let star = '*'.repeat(2 * i + 1);
    let space = ' '.repeat(input - i);
    console.log(space + star);
  }
}