요깨비's LAB

[백준, Back-Tracking, Kotlin] P.4344 평균은 넘겠지 본문

알고리즘(Kotlin)/Back-Tracking

[백준, Back-Tracking, Kotlin] P.4344 평균은 넘겠지

요깨비 2021. 4. 8. 15:17

 

import java.util.*

var C:Int = 0

fun main() {
    val scr = Scanner(System.`in`)

    C = scr.nextInt()

    val results = StringBuffer()
    for(i in 0 until C) {
        val N = scr.nextInt()
        val scores = mutableListOf<Int>()
        var total = 0
        for(j in 0 until N) {
            val score = scr.nextInt()
            total += score

            scores.add(score)
        }
        val avg = total/N
        var count = 0
        for(j in 0 until N) {
            if(scores[j] > avg)
                count++
        }

        val result = String.format("%.3f", count.toDouble()/N * 100)
        results.append("$result%\n")
    }

    print(results.toString())
}
Comments