11758 CCW

sycho·2024년 3월 10일
0

baekjoon-analysis

목록 보기
19/20

문제

https://www.acmicpc.net/problem/11758

Gold V

코드 (Kotlin)

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))
    val points = Array(3) { Pair(0, 0) }

    for (i: Int in points.indices) {
        val point = br.readLine()!!.split(" ").map{ x -> x.toInt() }
        points[i] = Pair(point[0], point[1])
    }
    br.close()

    bw.write(CCW(points).toString())
    bw.flush()
    bw.close()

}

fun CCW (points: Array<Pair<Int, Int>>): Int {
    var dir = 0
    for (i: Int in 0..2) {
        dir += points[i].first * points[(i+1)%points.size].second
    }
    for (i: Int in 0..2) {
        dir -= points[(i+1)%points.size].first * points[i].second
    }

    return if (dir > 0) 1
    else if (dir < 0) -1
    else 0
}

풀이

  • 풀이는 별거 없다. 그냥 CCW 적용 문제

  • 다만 Kotlin 문법 때문에 기록을 남긴다.

    bw.write(${CCW(points)})
profile
안 흔하고 싶은 개발자. 관심 분야 : 임베디드/컴퓨터 시스템 및 아키텍처/웹/AI

0개의 댓글