๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][1546][ํ‰๊ท ]

๋‰ด์ด NUEY 2023. 11. 20. 00:00
๋ฐ˜์‘ํ˜•

import java.util.Scanner;

// 1546	ํ‰๊ท 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int subjectNum = sc.nextInt();

		double m = 0;
		double sum = 0;
		double[] subjectArr = new double[subjectNum]; 
		
		for (int i = 0; i < subjectNum; i++) {
			subjectArr[i] = sc.nextInt();
		}
		sc.close();
		
		for (int i = 0; i < subjectArr.length; i++) { 
			m = Math.max(m, subjectArr[i]);
		}
		for (int i = 0; i < subjectArr.length; i++) {
			subjectArr[i] = subjectArr[i]/m*100;
			
			sum += subjectArr[i];
		}

		System.out.println(sum/subjectNum);
	}
}

 

  • ์ถœ๋ ฅ์ด 66.666667 ์ด๋Ÿฐ์‹์ด๊ธฐ ๋•Œ๋ฌธ์— double์— ๋‹ด์•„์ค˜์•ผ ํ•œ๋‹ค๋Š” ํ•จ์ •์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์ตœ๋Œ€๊ฐ’๋งŒ Math.max()๋ฅผ ์ด์šฉํ•ด ๊ตฌํ•ด์ฃผ๋ฉด ์‰ฝ๊ฒŒ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•