(1).백준 31663번 Mean Words는 많이 이상한 문제였는데

그냥 여러 글자들의 평균 값을 모아서 바꿔달라는 내용이었다.

 

처음엔 간단하게 생각하고 바로 처리하려고 헀지만

글자의 개수가 고정이 아니고 1000개까지 나올 수 있으면서

글자의 길이 또한 정해져 있지 않았기 때문에 아래에 진행하던 간단한 방법들은 폐기되었고

결국 라인별로 list에 글자들을 다 담아준 다음 한번에 숫자로 변환 및 평균값을 다시 문자화 하는 방식으로 해결했다.

 

list에 담을 때 먼저 숫자로 변환했으면 더 깔끔했을 것 같기도 하고

그러면 오히려 지저분한 코드가 됐을 것 같기도 하고

쓸일은 없는 문제지만 그래도 참 특이해서 생각보다는 시간을 잡아먹었다.

 

const input =`4
words
of
various
length`.split('\n')

const list = []
let str = ''
for(let i = 1 ; i <= Number(input[0]) ; i++){
    for(let j = 0 ; j < input[i].length ; j++){
        if(list[j]){
            list[j].push(input[i][j])
        }
        else{
            list[j] = [input[i][j]]
        }
    }

}

for(let i = 0 ; i < list.length ; i++){
    let sum = 0
    for(let j = 0 ; j < list[i].length ; j++){
        sum += list[i][j].charCodeAt()
    }
    str += String.fromCharCode((sum / list[i].length))
}

console.log(str)
// list.map(el => el.map(el => el.charCodeAt())).map(el => Math.ceil(...el))

// console.log(list.map(el => el.map(el => el.charCodeAt())))


// list.push(Math.ceil((input[1][i].charCodeAt() + input[2][i].charCodeAt())/2))
// console.log(String.fromCharCode(...list))
// charCodeAt 
// String.fromCharCode

'회고' 카테고리의 다른 글

[개발일지] - 776  (0) 2025.08.18
[개발일지] - 775(주말)  (5) 2025.08.17
[개발일지] - 773(광복절)  (0) 2025.08.15
[개발일지] - 772  (3) 2025.08.14
[개발일지] - 770  (1) 2025.08.12

+ Recent posts