본문 바로가기
백준

1546번: 평균

by bingual 2022. 2. 15.
반응형

 

 

 

 

 

 

 

풀이

 

실수형은 정확한 범위를위해 double을 사용한다. 최고점을 구하고 예제의 공식을 이용해 값을 계산한다.

 

 

 

 

 

자바

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

		StringTokenizer st = new StringTokenizer(br.readLine());
		double total = 0;
		double max = 0;
		double[] arr = new double[n];
		for (int i = 0; i < n; i++) {
			arr[i] = Double.parseDouble(st.nextToken());
			if (max < arr[i]) max = arr[i];			
		}	
		for (double score : arr) {
			total += score/max*100;
		}
		System.out.println(total/n);
    }
}

 

 

 

 

 

 

파이썬

n = int(input())

total = 0
max = 0
arr = list(map(int, input().split()))

arr.sort()
max = arr[-1]

for score in arr:
    total += score/max*100;

print(total/n)

 

'백준' 카테고리의 다른 글

14487번: 욱제는 효도쟁이야!!  (0) 2022.02.15
1173번: 운동  (0) 2022.02.15
1110번: 더하기 사이클  (0) 2022.02.15
2810번: 컵홀더  (0) 2022.02.15
11399번: ATM  (0) 2022.02.14