๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 9325๋ฒˆ : ์–ผ๋งˆ?

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 12. 23.

 

 

Algorithm

-  ์–ผ๋งˆ? -

 


 

๋ฌธ์ œ

ํ•ด๋นˆ์ด๋Š” ํ•™๊ต๋ฅผ ๋‹ค๋‹ˆ๋ฉด์„œ ํ‹ˆํ‹ˆํžˆ ๋ฒˆ ๋ˆ์œผ๋กœ ์ž๋™์ฐจ๋ฅผ ์‚ฌ๋ ค๊ณ  ํ•œ๋‹ค.

์ž๋™์ฐจ์— ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์˜ต์…˜์„ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š”๋ฐ ํ•ด๋นˆ์ด๋Š” ๋ง์…ˆ๊ณผ ๊ณฑ์…ˆ์„ ํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์นœ๊ตฌ ํƒœ์™„์ด์—๊ฒŒ ๋„์›€์„ ์ฒญํ–ˆ๋‹ค.

ํ•˜์ง€๋งŒ ํƒœ์™„์ด๋„ ๋ง์…ˆ๊ณผ ๊ณฑ์…ˆ์„ ๋ชปํ•œ๋‹ค. 

๋ถˆ์Œํ•œ ์ด ๋‘ ์นœ๊ตฌ๋ฅผ ์œ„ํ•ด ๋ชจ๋“  ์˜ต์…˜์ด ์ฃผ์–ด์ง„ ์ž๋™์ฐจ๋ฅผ ๊ตฌ๋งคํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์•ก์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด ์ฃผ์ž.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
	input.push(line.toString());
}).on("close", function () {
    input.shift();
    let result = [];
let carCost;
let option;
let i = 0;
while (true) {
	if (!input.includes(" ")) {
		carCost = +input[i++];
		option = +input[i++];
	}
	for (let j = 1; j <= option; j++) {
		let cost = input[i++].split(" ");
		carCost += +cost[0] * +cost[1];
	}
	console.log(carCost);
	if (i >= input.length) break;
}
	process.exit();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€