[BaekJoon] 10039번 - 평균 점수 [Java][C++]
[BaekJoon] 10039번 - 평균 점수 [Java][C++]
1. 문제 풀이
$40$ 점 이상이면 그 점수가 자신의 성적이고, $40$ 점 미만이면 보충학습을 듣는 조건으로 $40$ 점을 받으므로 최소 $40$ 점은 되게끔 점수를 받아서 평균을 구하면 된다.
2. 코드
1. 풀이 [Java]
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);
}
}
2. 풀이 [C++]
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(false);
cin.tie(nullptr);
int sum = 0;
for (int i = 0; i < 5; i++) {
int x;
cin >> x;
sum += max(x, 40);
}
cout << sum / 5;
}
This post is licensed under CC BY 4.0 by the author.