๊ฐ์ธ๊ณต๋ถ/Algorithm
[๋ฐฑ์ค][Node.js] 9325๋ฒ : ์ผ๋ง?
๐๋ฐ๋ด๋ด๐
2021. 12. 23. 22:46
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();
});
๋ฐ์ํ