본문 바로가기

BAEKJOON/JavaScript

[BAEKJOON] 평균은 넘겠지 (4344번)

// const input  = require("fs").readFileSync("/dev/stdin").toString().trim().split(" ");
const input  = require("fs").readFileSync("testCase/testCase.txt").toString().trim().split("\n");

function iGuessOverTheAvg(input) {
    for(let i = 1; i <input.length; i++) {
        let testCase = input[i].split(" ");
        let numOfStudents = testCase[0];
        let sum = 0;
        
        testCase.shift();

        for(let j = 0; j < numOfStudents; j++) {
            sum += Number(testCase[j]);
        }

        let avg = sum / numOfStudents;
        let overAvgCnt = 0;

        for(let k = 0; k < numOfStudents; k++) {
            if(testCase[k] > avg)
                overAvgCnt++;
        }
        console.log(`${(overAvgCnt / testCase.length * 100).toFixed(3)}%`);
    }
}

iGuessOverTheAvg(input);

'BAEKJOON > JavaScript' 카테고리의 다른 글

[BAEKJOON] 한수 (1065번)  (0) 2022.03.30
[BAEKJOON] 제로 (10773번)  (0) 2022.03.30
[BAEKJOON] 팰린드롬수 (1259번)  (0) 2022.03.29
[BAEKJOON] 평균 (1546번)  (0) 2022.03.28
[BAEKJOON] 상수 (2908번)  (0) 2022.03.28