티스토리 뷰
https://www.acmicpc.net/problem/1501
const input = require('fs').readFileSync('./dev/stdin').toString().trim().split('\n');
const N = +input.shift();
const dict = new Map();
for (let i = 0; i < N; i++) {
const word = input.shift().trim().split('');
const headTail = word.shift() + (word.pop() ?? '');
const body = word.sort().join('');
if (dict.has(headTail)) {
const subdict = dict.get(headTail);
if (subdict.has(body)) {
const cnt = subdict.get(body);
subdict.set(body, cnt + 1);
} else {
subdict.set(body, 1);
}
} else {
const subdict = new Map();
subdict.set(body, 1);
dict.set(headTail, subdict);
}
}
const answer = [];
const M = +input.shift();
for (let i = 0; i < M; i++) {
let tcAnswer = 0;
const words = input.shift().trim();
words.split(' ').forEach((word) => {
word = word.split('');
const headTail = word.shift() + (word.pop() ?? '');
const body = word.sort().join('');
if (dict.has(headTail)) {
const subdict = dict.get(headTail);
if (subdict.has(body)) {
if (tcAnswer == 0) tcAnswer = 1;
tcAnswer *= subdict.get(body);
}
}
});
answer.push(tcAnswer);
}
console.log(answer.join('\n'));
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 17839번: Baba is Rabbit (0) | 2023.09.13 |
---|---|
Node.js) 백준 20311번: 화학 실험 (0) | 2023.09.13 |
Node.js) 백준 23254번: 나는 기말고사형 인간이야 (0) | 2023.09.13 |
Node.js) 백준 21773번: 가희와 프로세스 1 (0) | 2023.09.12 |
Node.js) 백준 17178번: 줄서기 (0) | 2023.09.12 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- create databases;
- MySQL
- 면접비
- 로드나인
- 서버점검
- 면접질문
- 최소공통조상
- create db
- BFS
- 롱베케이션
- 다이나믹프로그래밍
- node.js
- 다이나밍프로그래밍
- 투포인터 연습
- 동적프로그래밍
- MOD
- 그래프
- 은둔청년체험
- 투포인터
- DB 생성
- 개발자면접
- 서버개발
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함