[알고리즘/백준] 1546 평균(자바)

[알고리즘/백준] 1546 평균(자바)

문제

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); } }

728x90

from http://developer-hm.tistory.com/143 by ccl(A) rewrite - 2021-09-18 17:01:15