[백준] 1546번 : 평균

chezze·2023년 5월 11일
0

백준 알고리즘

목록 보기
1/3
post-thumbnail

문제 링크

부동 소수점, 고정 소수점에 대한 개념과 사용법을 알고 있다면 풀기 쉬운 문제였다.

#include <iostream>
#include <vector>

int main(void) {
    // Declare variable
    unsigned int numberOfSubject;
    unsigned int maxOfScore = 0;
    unsigned int sumOfScore = 0;
    long double result;
    std::vector<unsigned int> scoreVector;

    // Input
    std::cin >> numberOfSubject;

    // Vector setting
    for(int i = 0; i < numberOfSubject; i++) {
        unsigned int score;
        std::cin >> score;
        sumOfScore += score;
        scoreVector.push_back(score);
        if(maxOfScore < score) {
            maxOfScore = score;
        }
    }

    // Set Precision
    std::cout.precision(15);
    
    // Change to Fixed-Point Representation
    std::cout << std::fixed;

    // Caculate result
    result = (long double) (sumOfScore * 100) / (maxOfScore * numberOfSubject);

    // Output
    std::cout << result << std::endl;
}
profile
주니어 컴공학부생🌱

0개의 댓글