문제링크
data class Position(val x: Int, val y: Int, val z: Int)
fun main() {
val bufferedReader = System.`in`.bufferedReader()
val bufferedWriter = System.out.bufferedWriter()
val positions = mutableListOf<Position>()
repeat(3) {
val (x, y) = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
positions.add(Position(x, y, 0))
}
val abVector = getVector(positions[0], positions[1])
val acVector = getVector(positions[0], positions[2])
val crossProduct = getCrossProduct(abVector, acVector)
when {
crossProduct.z == 0 -> bufferedWriter.write("0")
crossProduct.z > 0 -> bufferedWriter.write("1")
else -> bufferedWriter.write("-1")
}
bufferedReader.close()
bufferedWriter.close()
}
fun getVector(position1: Position, position2: Position): Position {
return Position(position2.x - position1.x, position2.y - position1.y, 0)
}
fun getCrossProduct(vector1: Position, vector2: Position): Position {
return Position(
(vector1.y * vector2.z) - (vector1.z * vector2.y),
(vector1.z * vector2.x) - (vector1.x * vector2.z),
(vector1.x * vector2.y) - (vector1.y * vector2.x)
)
}
주석 없는 코드를 만들기 위해 노력하는 개발자입니다.
혹시라도 의도가 분명하지 않아보이는 (이해가 되지 않는) 코드가 있으시다면 편하게 답변 달아주시면 정말 감사하겠습니다.