코딩하는 개굴이

[HackerRank] Compare Triplets (Kotlin) 본문

알고리즘/HackerRank

[HackerRank] Compare Triplets (Kotlin)

개굴이모자 2022. 7. 9. 16:21
반응형

Compare Triplets : https://www.hackerrank.com/challenges/compare-the-triplets/problem

 

Compare the Triplets | HackerRank

Compare the elements in two triplets.

www.hackerrank.com

간단한 문제이다. 

fun compareTriplets(a: Array<Int>, b: Array<Int>): Array<Int> {
    // Write your code here
    var aScore = 0
    var bScore = 0
    for(i in a.indices) {
        if(a[i] < b[i]) bScore++
        else if(a[i] > b[i]) aScore++
    }

    val arr = Array(2) { 0 }
    arr[0] = aScore
    arr[1] = bScore
    return arr
}

fun main(args: Array<String>) {

    val a = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()

    val b = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()

    val result = compareTriplets(a, b)

    println(result.joinToString(" "))
}
반응형

'알고리즘 > HackerRank' 카테고리의 다른 글

[HackerRank] Extra Long Factorials (Kotlin)  (0) 2022.07.30
[HackerRank] Super Reduced String (Kotlin)  (0) 2022.07.09
Comments