문제링크
import kotlin.math.sqrt
fun main() {
val bufferedReader = System.`in`.bufferedReader()
val bufferedWriter = System.out.bufferedWriter()
val positions = bufferedReader.readLine().split(" ").map { it.toInt() }
if (isSameGradient(positions)) bufferedWriter.write("-1.0")
else {
val distances = mutableListOf<Double>()
distances.add(getDistance(positions[0], positions[1], positions[2], positions[3]))
distances.add(getDistance(positions[2], positions[3], positions[4], positions[5]))
distances.add(getDistance(positions[4], positions[5], positions[0], positions[1]))
distances.sort()
bufferedWriter.write("${(distances[2] - distances[0]) * 2}")
}
bufferedReader.close()
bufferedWriter.close()
}
fun isSameGradient(positions: List<Int>): Boolean {
return getGradient(positions[0], positions[1], positions[2], positions[3]) ==
getGradient(positions[2], positions[3], positions[4], positions[5])
}
fun getGradient(x1: Int, y1: Int, x2: Int, y2: Int): Double {
if (y1 - y2 == 0) return 0.0
return (x1 - x2).toDouble() / (y1 - y2)
}
fun getDistance(x1: Int, y1: Int, x2: Int, y2: Int): Double {
return sqrt(((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)).toDouble())
}
주석 없는 코드를 만들기 위해 노력하는 개발자입니다.
혹시라도 의도가 분명하지 않아보이는 (이해가 되지 않는) 코드가 있으시다면 편하게 답변 달아주시면 정말 감사하겠습니다.