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

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

[๋ฐฑ์ค€/Node.js] 10810๋ฒˆ ํ’€์ด || JavaScript

728x90
let input = require('fs').readFileSync('/dev/stdin').toString().trim().split("\n").map(i => i.split(" "));

const infoArr = input[0].map(i => Number(i)); //[5, 4]
const basketCount = infoArr[0]; //๋ฐ”๊ตฌ๋‹ˆ ๊ฐœ์ˆ˜ 5
const loop = infoArr[1]; //ํ–‰์˜ ๊ฐœ์ˆ˜ 4

let basket = new Array(basketCount);

for (let i = 0; i < basketCount; i++) {
    basket[i] = 0;
}

for (let i = 1; i <= loop; i++) {
    const rangeInfo = input[i].map(i => Number(i));
    let from = rangeInfo[0] - 1;
    let to = rangeInfo[1] - 1;
    let ballNumber = rangeInfo[2];
    for (let k = from; k <= to; k++) {
        basket[k] = ballNumber;
    }
}
console.log(...basket);

 

๋ฌธ์ œ๋„ ๋„ˆ๋ฌด ๊ธธ๊ณ  ์“ธ๋ฐ์—†์ด ์•ŒํŒŒ๋ฒณ๋„ ๋งŽ์•„์„œ ๋ฌธ์ œ๋ฅผ ๋ถ„์„ํ•˜๋Š” ์‹œ๊ฐ„๋ถ€ํ„ฐ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋‹ค.

๋ฐฐ์—ด์— ๋Œ€ํ•œ ํ•จ์ˆ˜๋ฅผ ์ž˜ ๋ชฐ๋ผ์„œ ์–ด๋–ป๊ฒŒ ํ’€์ง€ ํ•˜๋‹ค๊ฐ€ 

for ๋ฌธ์„ ์—ฌ๋Ÿฌ๋ฒˆ ๋Œ๋ ค์„œ ํ•ด๊ฒฐํ–ˆ๋‹ค.

 

์ฒ˜์Œ์— ๊ฐ€์ ธ์™€์•ผํ•˜๋Š”๊ฒŒ ๋ฐ”๊ตฌ๋‹ˆ์˜ ์ˆ˜์™€ ํ–‰์ด ๋ช‡๊ฐœ ์žˆ๋Š”์ง€ (๊ณต๋†€์ด๋ฅผ ๋ช‡๋ฒˆํ•˜๋Š”์ง€) ๋ฅผ ์•Œ์•„์•ผํ•˜๊ณ 

์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ชจ๋“  ๋ฐ”๊ตฌ๋‹ˆ์— 0์„ ๋„ฃ์–ด์ค€๋‹ค. 

๋จผ์ € ๋„ฃ์–ด์ฃผ๋Š”๊ฒŒ ํŽธํ•ด์„œ ๋จผ์ € ๋„ฃ์–ด์คฌ๋‹ค. ์•ˆ๊ทธ๋Ÿผ ๋‚˜์ค‘์— ๊ฐ’์ด ์—†๋Š”๊ฑธ ๋”ฐ๋กœ ์ฐพ์•„์•ผํ•˜๋‹ˆ๊นŒ ๊ท€์ฐฎ.

 

๊ทธ ๋‹ค์Œ์—” 2๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ ์ฃผ์–ด์ง„ ๋ฒ”์œ„์™€ ๊ณต์— ์จ์žˆ๋Š” ์ˆ˜๋ฅผ ์ฐธ์กฐํ•ด์„œ for๋ฌธ์„ ๋งŒ๋“ค์—ˆ๋‹ค.

๋ฐ”๊ตฌ๋‹ˆ์˜ ์ˆซ์ž์—์„œ 1์„ ๋นผ์•ผ index์˜ ์ˆซ์ž๊ฐ€ ๋œ๋‹ค๋Š” ์ ์„ ๊ธฐ์–ตํ•ด์•ผํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์ฃผ์–ด์ง„ ๋ฒ”์œ„์— ๊ณต์— ์จ์žˆ๋Š” ๋ฒˆํ˜ธ๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค. ๐Ÿ€

 

 

๊ทธ๋‚˜์ €๋‚˜ ๋ฐฑ์ค€ ํ—ˆ๋ธŒ๋ฅผ ์“ฐ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, 

์˜ค๋Š˜์€ ๊นƒํ—™์— ์•ˆ์˜ฌ๋ผ๊ฐ€๋Š”๊ฒƒ...!

 

ใ… ใ…  ์ดํ‹€๋งŒ์— ํ’€์—ˆ๋Š”๋ฐ,,

 

๋ณด๋‹ˆ๊นŒ CORS ๋ฌธ์ œ๋กœ ์ด์Šˆ๊ฐ€ ์ƒ์„ฑ๋˜๊ณ  ์žˆ์—ˆ๋‹ค.

CORS ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ ๋„๋ฉด ๋˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค๊ณ ๋“ค ํ•˜์ง€๋งŒ ์ด๋ฒˆ์—” ์•ˆ๊ทธ๋Ÿฐ๊ฒƒ ๊ฐ™๋‹ค.ใ… 

์—ด์‹ฌํžˆ ํ’€์–ด์„œ ๋งž์ท„๋Š”๋ฐ ์•ˆ์˜ฌ๋ผ๊ฐ€๋‹ˆ๊นŒ ์•„์‰ฝ๋‹ค ๐Ÿ˜ž ๐ŸŒฟ

 

 

728x90
๋ฐ˜์‘ํ˜•