(1).백준 9046번 복호화는 결론적으로는 최다 등장 문자열을 찾아야 하는 문제였기 때문에
각각 횟수를 기록한 다음 Math.max와 구조분해할당으로 최대값을 찾아서
해당 값이 두개 이상인 경우 ?, 아닌 경우 해당하는 문자를 출력하는 방식으로 처리했다.
const input = `3
asvdge ef ofmdofn
xvssc kxvbv
hull full suua pmlu`.split('\n')
for(let i = 1 ; i < input.length ; i++){
const map = {}
for(let j = 0 ; j < input[i].length ; j++){
if(input[i][j] == ' '){
continue
}
else if(map[input[i][j]]){
map[input[i][j]]++
}
else{
map[input[i][j]] = 1
}
}
const max = Math.max(...Object.values(map))
let result = ''
for(let key in map){
if(map[key] == max){
if(result == ''){
result = key
}
else{
result = '?'
break
}
}
}
console.log(result)
}'회고' 카테고리의 다른 글
| [개발일지] - 881(연차) (0) | 2025.12.09 |
|---|---|
| [개발일지] - 880(주말) (0) | 2025.12.08 |
| [개발일지] - 878 (0) | 2025.12.06 |
| [개발일지] - 877 (0) | 2025.12.04 |
| [개발일지] - 876 (0) | 2025.12.04 |
