๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„์—” ๊ณต๋ถ€/๐Ÿซง ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€

[๋ฐฑ์ค€/Node.js] 2444๋ฒˆ ๋ณ„์ฐ๊ธฐ || ํ’€์ด JavaScript

728x90
const input = require('fs').readFileSync('/dev/stdin').toString();
const N = +input;
const spaceStart = N - 1; //4
const resultLength = 2 * N - 1; //9

for (let i = spaceStart; i >= 0; i--) {
    let resultArr = new Array(resultLength);
    let star = resultLength - (2 * i);
    resultArr.fill(" ", 0, i);
    resultArr.fill("*", i, i + star);
    console.log(resultArr.join(""));
}
for (let i = 1; i < spaceStart + 1; i++) {
    let reversArr = new Array(resultLength);
    let star = resultLength - (2 * i);
    reversArr.fill(" ", 0, i);
    reversArr.fill("*", i, i + star);
    console.log(reversArr.join(""));
}

 

์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๋ถ„๋ช… ์ถœ๋ ฅ์ด ์ž˜ ๋˜๋Š”๋ฐ๋„ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋‚˜์™”๋‹ค. 

์ˆซ์ž๋ฅผ ๋ฐ”๊ฟจ๋Š”๋ฐ๋„ ์ถœ๋ ฅ์ด ์ž˜ ๋๊ณ , ์ถœ๋ ฅํ•œ ๋ฌธ์ž์˜ ๋’ท๋ถ€๋ถ„์—๋„ ์—ฌ๋ฐฑ์ด ์—†์—ˆ๋‹ค. 

 

์›์ธ์„ ์ฐพ์•˜๋Š”๋ฐ, ์ฒ˜์Œ input์˜ ๊ฐ’์„ ์ž˜๋ชป ์ง€์ •ํ–ˆ์—ˆ๋‹ค. 

input[0] ์„ ํ•ด๋‘ฌ์„œ 

10์„ ์ž…๋ ฅํ•ด๋„ N ์œผ๋กœ 1์ด ๋“ค์–ด์™”๋‹ค.

 

ํ›„.... 

์ถœ๋ ฅ์„ ํ•œ๋ฒˆ์— ํ•˜๋ผ๋Š”๊ฑด๊ฐ€? ํ•˜๋ฉด์„œ ์“ธ๋ฐ์—†๋Š” ๊ฒƒ๋งŒ ๋ฐ”๊พธ๊ณ  ์žˆ์—ˆ์Œ.. 

๋ฌดํŠผ.. ๋•Œ๋ ค์น˜๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์ฐธ๊ณ  ์„ฑ๊ณตํ–ˆ๋‹ค!!

 

์˜ค๋Š˜์˜ ๊ตํ›ˆ

๐Ÿ“Œ input ๊ฐ’๋ถ€ํ„ฐ ์ œ๋Œ€๋กœ ๋ฐ›์•„์˜ค์ž. 

 

728x90
๋ฐ˜์‘ํ˜•