원본 문제 : https://www.acmicpc.net/problem/1931
문제 참고 : https://ju-nam2.tistory.com/44
<첫번째>
import java.util.*
class Meeting : Comparable<Meeting> {
var start: Int = 0
var end: Int = 0
constructor(start: Int, end: Int) {
this.start = start
this.end = end
}
override fun compareTo(other: Meeting): Int {
if (this.end == other.end) {
return Integer.compare(this.start, other.end)
} else {
return Integer.compare(this.end, other.end)
}
}
}
fun main() {
val sc: Scanner = Scanner(System.`in`)
val N: Int = sc.nextInt()
val list: ArrayList<Meeting> = ArrayList()
for (i in 0 until N) {
list.add(Meeting(sc.nextInt(), sc.nextInt()))
}
list.sort()
var cnt: Int = 1
var endTime: Int = list[0].end
for (i in 1 until N) {
if (list[i].start>=endTime) {
endTime = list[i].end
cnt++
}
}
println(cnt)
}
'코딩연습' 카테고리의 다른 글
[백준] 로또 (6603)(Kotlin) (0) | 2020.02.26 |
---|---|
[백준] 퇴사 (14501)(Kotlin) (0) | 2020.02.26 |
[백준] 동전 0 (11047)(Kotlin) (0) | 2020.02.20 |
[백준] ATM (11399)(Kotlin) (0) | 2020.02.20 |
[백준] 상범 빌딩 (6593)(Kotlin) (0) | 2020.02.20 |
댓글