https://www.acmicpc.net/problem/1157
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().toUpperCase().split("");
const dic = {};
input.forEach((i) => {
if(dic[i] === undefined) {
dic[i] = 1;
} else {
dic[i] += 1;
}
});
const keyList = Object.keys(dic);
const list = [];
let cnt = 0;
let maxKey = '';
keyList.forEach((key) => {
list.push(dic[key]);
});
let max = Math.max(...list);
keyList.forEach((key) => {
if(dic[key] === max) {
maxKey = key;
cnt++;
}
if(cnt > 1) return false;
});
if(cnt > 1) console.log("?");
else console.log(maxKey);
728x90
'Algorithm\CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] [1316] 그룹 단어 체커 (0) | 2023.02.09 |
---|---|
[Baekjoon] [10773] 제로 (0) | 2023.02.09 |
[Baekjoon] [4344] 평균은 넘겠지 (0) | 2023.02.09 |
[Baekjoon] [2941] 크로아티아 알파벳 (0) | 2023.02.09 |
[Baekjoon] [10926] ??! (0) | 2023.02.09 |