λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
κ°œμΈκ³΅λΆ€/Algorithm

[λ°±μ€€][Node.js] 9375번 : νŒ¨μ…˜μ™• μ‹ ν•΄λΉˆ

by πŸ‡λ°•λ΄‰λ΄‰πŸ‡ 2021. 12. 24.

 

 

Algorithm

-  νŒ¨μ…˜μ™• μ‹ ν•΄λΉˆ -

 


 

문제

ν•΄λΉˆμ΄λŠ” νŒ¨μ…˜μ— 맀우 λ―Όκ°ν•΄μ„œ ν•œλ²ˆ μž…μ—ˆλ˜ μ˜·λ“€μ˜ 쑰합을 μ ˆλŒ€ λ‹€μ‹œ μž…μ§€ μ•ŠλŠ”λ‹€.

예λ₯Ό λ“€μ–΄ 였늘 ν•΄λΉˆμ΄κ°€ μ•ˆκ²½, μ½”νŠΈ, μƒμ˜, μ‹ λ°œμ„ μž…μ—ˆλ‹€λ©΄, λ‹€μŒλ‚ μ€ 바지λ₯Ό μΆ”κ°€λ‘œ μž…κ±°λ‚˜ μ•ˆκ²½λŒ€μ‹  렌즈λ₯Ό μ°©μš©ν•˜κ±°λ‚˜ ν•΄μ•Όν•œλ‹€.

ν•΄λΉˆμ΄κ°€ 가진 μ˜μƒλ“€μ΄ μ£Όμ–΄μ‘Œμ„λ•Œ κ³Όμ—° ν•΄λΉˆμ΄λŠ” μ•ŒλͺΈμ΄ μ•„λ‹Œ μƒνƒœλ‘œ λ©°μΉ λ™μ•ˆ 밖에 λŒμ•„λ‹€λ‹ 수 μžˆμ„κΉŒ?

 

μž…μΆœλ ₯ μ˜ˆμ‹œ

 

문제 ν’€κΈ°

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin")
		.toString()
		.split("\n");

let number = 0;
for (let i = 1; i <= +input[0]; i++) {
	let obj = {};
	let t = +input[++number];
	for (let j = 1; j <= t; j++) {
		input[j + number] = input[j + number].split(" ");
		let cloth = input[j + number][0];
		let kinds = input[j + number][1];
		if (obj[kinds]) {
			obj[kinds].push(cloth);
		} else {
			obj[kinds] = [cloth];
		}
	}

	number += t;

	let count = 1;
	for (let key in obj) {
		count *= obj[key].length + 1;
	}
	console.log(count - 1);
}

 

 

 

λ°˜μ‘ν˜•

λŒ“κΈ€