티스토리 뷰

https://www.acmicpc.net/problem/15312

 

15312번: 이름 궁합

영어 대문자 알파벳 26개의 획수는 순서대로 3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1 로 정한다. (출제자가 알파벳 대문자를 쓰는 방법이 기준이다)

www.acmicpc.net

const [A, B] = require('fs')
	.readFileSync('./dev/stdin')
	.toString()
	.trim()
	.split('\n')
	.map((v) => v.trim());
const line = [3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1];

let arr = [];

for (let i = 0; i < A.length; i++) {
	const a = A.charCodeAt(i) - 65;
	const b = B.charCodeAt(i) - 65;
	arr.push(line[a]);
	arr.push(line[b]);
}

while (arr.length > 2) {
	let newArr = [];
	for (let i = 0; i < arr.length - 1; i++) {
		const next = (arr[i] + arr[i + 1]) % 10;
		newArr.push(next);
	}
	arr = newArr;
}

console.log(arr.join(''));
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함