티스토리 뷰
https://www.acmicpc.net/problem/1213
1213번: 팰린드롬 만들기
첫째 줄에 문제의 정답을 출력한다. 만약 불가능할 때는 "I'm Sorry Hansoo"를 출력한다. 정답이 여러 개일 경우에는 사전순으로 앞서는 것을 출력한다.
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim();
let count = [];
for (let i = 0; i < input.length; i++) {
const x = input.charCodeAt(i) - 65;
if (count[x]) {
count[x]++;
} else {
count[x] = 1
}
}
const odd = count.filter(v => v % 2 != 0);
if (odd.length > 1) {
console.log("I'm Sorry Hansoo");
} else {
let head = '';
let body = '';
let tail = '';
count.forEach((v, i) => {
if (v % 2 != 0) {
body += String.fromCharCode(i + 65);
v--;
}
for (let k = 0; k < v / 2; k++) {
head += String.fromCharCode(i + 65);
tail = String.fromCharCode(i + 65) + tail
}
})
console.log(head + body + tail)
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 3986번 : 좋은 단어 (0) | 2022.03.08 |
---|---|
Node.js) 백준 1940번 : 주몽 (0) | 2022.03.08 |
Node.js) 백준 1620번 : 나는야 포켓몬 마스터 이다솜 (0) | 2022.03.07 |
Node.js) 백준 2559번 : 수열 (0) | 2022.03.07 |
Node.js) 백준 9996번 : 한국이 그리울 땐 서버에 접속하지 (0) | 2022.03.07 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- MySQL
- DB 생성
- 최소공통조상
- 서버점검
- node.js
- 투포인터 연습
- 개발자면접
- create db
- 면접질문
- MOD
- 다이나밍프로그래밍
- create databases;
- 그래프
- 다이나믹프로그래밍
- 서버개발
- 투포인터
- 롱베케이션
- 동적프로그래밍
- 로드나인
- 은둔청년체험
- 면접비
- BFS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함