알고리즘/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(" "))
}
반응형