알고리즘 및 자료구조/문제
백준알고리즘 1546번 평균
ktko
2018. 4. 23. 23:17
백준알고리즘
https://www.acmicpc.net/problem/1546
예시는 두 가지 과목을 주었고 문제 예시에는 3가지 과목을 주어서 약간 혼동이 있었다.
문제 설명에 대한 예제가 3가지 과목을 입력받고 40 + 80 + 60 / 최고점(80) * 100 / 3(입력받은 과목)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int count = Integer.parseInt(scan.nextLine().trim()); int[] calArray = new int[count]; int max = 0; int total = 0; for(int i = 0; i < count; i++) { calArray[i] = (scan.nextInt()); max = Math.max(max, calArray[i]); total += calArray[i]; } int average = total * 100 / max ; System.out.printf("%.2f",(float)average / calArray.length); } }