[BaekJoon] #10039 - 평균 점수 [Java][C++]
[BaekJoon] #10039 - 평균 점수 [Java][C++]
1. 아이디어
40점 이상이면 그 점수가 자신의 성적이고, 40점 미만이면 보충학습을 듣는 조건으로 40점을 받으므로 최소 40점은 되게끔 점수를 받아서 평균을 구하면 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
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;
}
This post is licensed under CC BY 4.0 by the author.