본문 바로가기

IT/알고리즘

[백준] 덩치

728x90
SMALL

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

 

class Person(val weight: Int, val height: Int)

fun main() = with(Scanner(System.`in`)) {
    val count = nextInt()
    val items = mutableListOf<Person>()
    val results = Array<Int>(count) { 1 }

    for (i in 0 until count) {
        val weight = nextInt()
        val height = nextInt()
        items.add(Person(weight = weight, height = height))
    }

    for (i in 0 until items.size) {
        var result = 0
        for (j in 0 until items.size) {
            if (items[i].weight < items[j].weight && items[i].height < items[j].height) {
                result += 1
            }
        }
        results[i] = result + 1
    }

    println(results.joinToString(" "))
}
728x90
LIST

'IT > 알고리즘' 카테고리의 다른 글