문제
https://www.acmicpc.net/problem/1546
시험 점수를 입력받아 최고 점수를 기준으로 점수를 조정한 후 평균을 구하는 문제였다.
문제 풀이
1. Scanner
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
if (N <= 1000) {
double sum = 0;
double maxScore = Integer.MIN_VALUE;
for (int i = 0; i < N; i++) {
int a = scanner.nextInt();
if (a <= 100 && a > 0) {
sum += a;
if (a > maxScore) {
maxScore = a;
}
}
}
double average = (sum / maxScore) * 100 / N;
System.out.println(average);
}
scanner.close();
}
}
2. BufferedReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
if (N <= 1000) {
double sum = 0;
double maxScore = Integer.MIN_VALUE;
String[] scores = reader.readLine().split(" ");
for (int i = 0; i < N; i++) {
int a = Integer.parseInt(scores[i]);
if (a <= 100 && a > 0) {
sum += a;
if (a > maxScore) {
maxScore = a;
}
}
}
double average = (sum / maxScore) * 100 / N;
System.out.println(average);
}
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
[백준/JAVA]2743번 단어 길이 재기 (0) | 2025.01.14 |
---|---|
[백준/JAVA]27866번 문자와 문자열 (0) | 2025.01.13 |
[백준/JAVA]10811번 바구니 뒤집기 (0) | 2025.01.13 |
[백준/JAVA]3052번 나머지 (0) | 2025.01.10 |
[백준/JAVA]5597번 과제 안 내신 분..? (0) | 2025.01.10 |