문제링크
data class Position(val x: Int, val y: Int)
fun main() {
val bufferedReader = System.`in`.bufferedReader()
val bufferedWriter = System.out.bufferedWriter()
val t = bufferedReader.readLine().toInt()
repeat(t) {
val positions = mutableListOf<Position>()
repeat(4) {
val (x, y) = bufferedReader.readLine().split(" ").map { it.toInt() }
positions.add(Position(x, y))
}
val lengths = mutableListOf<Int>()
for (i in 0 until positions.size) {
for (j in i + 1 until positions.size) {
lengths.add(getDistance(positions[i], positions[j]))
}
}
lengths.sort()
if (lengths[0] == lengths[1] && lengths[1] == lengths[2] && lengths[2] == lengths[3] && lengths[4] == lengths[5])
bufferedWriter.write("1\n")
else bufferedWriter.write("0\n")
}
bufferedReader.close()
bufferedWriter.close()
}
fun getDistance(fromPosition: Position, toPosition: Position): Int {
return (fromPosition.x - toPosition.x) * (fromPosition.x - toPosition.x) + (fromPosition.y - toPosition.y) * (fromPosition.y - toPosition.y)
}
주석 없는 코드를 만들기 위해 노력하는 개발자입니다.
혹시라도 의도가 분명하지 않아보이는 (이해가 되지 않는) 코드가 있으시다면 편하게 답변 달아주시면 정말 감사하겠습니다.