[Java | 백준 1546] 평균
· 테크· Java
Java
백준 1546번 www.acmicpc.net/problem/1546
풀이
여기서 주의할 점은 double 타입으로 계산해야 한다는 점이다. 문제에서 알 수 있듯이 오차의 범위는 값은 반드시 소수 2자리까지 출력해야 하는 것을 뜻하는 것이 아니라는 것을 알아야 한다.
double 타입의 배열로 점수를 받고 가장 최대값을 구한다. 이 최대값과 각각의 점수가 이미 double 타입으로 초기화 되어 있으므로 계산해서 나온 값 sum 역시 double 타입이다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import java.util.*;
public class Array_1546 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
double max=0, sum=0;
double[] arr = new double[x];
for (int i=0; i<x; i++) {
arr[i]=sc.nextDouble();
if(arr[i]>max)
max=arr[i];
}
for (int i=0; i<x; i++) {
arr[i]=arr[i]/max*100;
sum += arr[i];
}
System.out.println(sum/x);
sc.close();
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319