티스토리 뷰
https://www.acmicpc.net/problem/9375
9375번: 패션왕 신해빈
첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.
www.acmicpc.net
const fs = require('fs');
const [n, ...arr] = fs.readFileSync("./dev/stdin").toString().trim().split("\n");
let clothes = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i].includes(' ')) {
let temp = arr[i].split(' ');
clothes[clothes.length - 1].push(temp)
} else {
clothes.push([])
}
}
clothes.forEach(arr => {
let cloth = {};
arr.forEach(v => {
if (cloth.hasOwnProperty(v[1])) {
cloth[v[1]]++;
} else {
cloth[v[1]] = 1;
}
})
let clothArr = Object.entries(cloth);
if (clothArr.length == 1) {
console.log(clothArr[0][1]);
}
else {
console.log(clothArr.reduce((r, v) => { return r * (v[1] + 1) }, 1) - 1)
}
})
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 2004번 : 조합 0의 개수 ★ (0) | 2021.09.13 |
---|---|
Node.js) 백준 1676번 : 팩토리얼 0의 계수 (0) | 2021.09.13 |
Node.js) 백준 1010번 : 다리 놓기 (0) | 2021.09.13 |
Node.js) 백준 11051번 : 이항 계수 2 (1) | 2021.09.12 |
Node.js) 백준 11050번 : 이항계수 1 (0) | 2021.09.12 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 면접비
- 로드나인
- 투포인터
- 면접질문
- 롱베케이션
- DB 생성
- MySQL
- BFS
- 개발자면접
- 그래프
- create db
- KMP
- 동적프로그래밍
- node.js
- MOD
- 투포인터 연습
- 은둔청년체험
- 다이나믹프로그래밍
- create databases;
- 서버개발
- 서버점검
- 최소공통조상
- 다이나밍프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함