IT/알고리즘

[백준] 단어수학

남갯 2024. 11. 11. 20:34
SMALL

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

 

 

fun main() = with(Scanner(System.`in`)) {
    val maxNumber = nextInt()
    val arr: Array<String> = Array(maxNumber) { "" }
    for (i in 0 until maxNumber) {
        arr[i] = next()
    }

    val map: MutableMap<Char, Int> = mutableMapOf()

    for (text in arr) {
        for (i in text.indices) {
            map[text[i]] = map.getOrDefault(text[i], 0) + 10.0.pow((text.length - 1 - i).toDouble()).toInt()
        }
    }
    var result = 0
    map.keys.sortedByDescending { map[it] }.forEachIndexed() { i, it ->
        result += map[it]!! * (9 - i)
    }
    p
LIST