728x90
문제
https://www.acmicpc.net/problem/1546
풀이 코드
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int max = Integer.MIN_VALUE; //최고 점수
int[] scores = new int[n]; //점수 저장
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
scores[i] = Integer.parseInt(st.nextToken());
max = Math.max(max, scores[i]);
}
double sum = 0;
for (int score : scores) {
//score, max 모두 정수형 int이기 때문에 실수형 double로 타입 캐스팅
sum += (double)score/max*100;
}
System.out.println(sum/n);
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[알고리즘/백준] 2439 별찍기 - 2(자바, StringBuilder) (0) | 2021.09.18 |
---|---|
[알고리즘/백준] 2438 별찍기 - 1 (자바, StringBuilder) (0) | 2021.09.18 |
[백준] 1157 단어 공부(자바) (0) | 2021.09.18 |
[백준] 1152 단어의 개수 - 자바, StringTokenizer (0) | 2021.09.17 |
[백준] 2914 저작권 - 자바 (0) | 2021.09.16 |
댓글