Post

[BaekJoon] #10039 - 평균 점수 [Java][C++][Python]

[BaekJoon] #10039 - 평균 점수 [Java][C++][Python]

문제 링크


1. 아이디어

40점 미만인 점수를 40점으로 바꾼 5명의 평균을 구하는 문제다. 각 점수와 40 중 큰 값이 곧 보정된 점수이고, 보정된 점수도 모두 5의 배수라 합도 5의 배수여서 5로 나누면 나머지 없이 평균이 나온다.


2. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int sum = 0;
        for (int i = 0; i < 5; i++) {
            sum += Math.max(Integer.parseInt(br.readLine()), 40);
        }

        System.out.println(sum / 5);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int sum = 0;
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        sum += max(x, 40);
    }

    cout << sum / 5;
}
1
2
3
4
5
6
7
8
9
import sys

input = sys.stdin.readline

total = 0
for _ in range(5):
    total += max(int(input()), 40)

print(total // 5)

This post is licensed under CC BY 4.0 by the author.