코딩연습
[백준] 회의실배정 (1931)(Kotlin)
유줘니
2020. 2. 20. 16:52
원본 문제 : 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)
}