Algorithm/📖Baekjoon
#7568 덩치
yewoneeee
2024. 7. 26. 02:18
문제
코드
fun main() = with(System.`in`.bufferedReader()) {
val n = readLine().toInt()
val group: MutableList<Person> = mutableListOf()
repeat(n) {
val (h, w) = readLine().split(" ").map { it.toInt() }
group.add(Person(h, w))
}
group.forEach {
for (p in group) {
if (it.height < p.height && it.weight < p.weight) it.rank++
}
print("${it.rank} ")
}
}
class Person(val height: Int, val weight: Int, var rank: Int = 1)
풀이
처음엔 정렬로 풀어야 하나 싶었다.
근데 키와 몸무게 중 하나만 큰 경우엔 어떤 방식으로 정렬해야할지 모르겠더라
N이 생각보다 작길래 그냥 이중 for문으로 모두 확인했다.