728x90
반응형
https://www.acmicpc.net/problem/1546
1546번: 평균
첫째 줄에 시험 본 과목의 개수 N이 주어진다. 이 값은 1000보다 작거나 같다. 둘째 줄에 세준이의 현재 성적이 주어진다. 이 값은 100보다 작거나 같은 음이 아닌 정수이고, 적어도 하나의 값은 0보
www.acmicpc.net
배열을 이용한 풀이
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
import javax.swing.plaf.synth.SynthSeparatorUI;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = null;
//테스스 수
int num = Integer.parseInt(br.readLine());
double [] score = new double[num];
double sum = 0;
st = new StringTokenizer(br.readLine(), " ");
double temp = 0;
for(int i=0; i<num; i++) {
int sc = Integer.parseInt(st.nextToken());
if(temp < sc) {
temp = sc;
}
score[i] = sc;
}
double result = 0;
for(int i=0; i<num; i++) {
result = score[i]/temp*100;
sum+=result;
}
bw.write(sum/num+"\n");
bw.flush();
bw.close();
}
}
|
cs |
728x90
반응형
'알고리즘' 카테고리의 다른 글
백준 알고리즘 2439번: 별 찍기 - 2 - JAVA (0) | 2022.12.08 |
---|---|
백준 알고리즘 2438번: 별 찍기 - 1 - JAVA (0) | 2022.12.08 |
자료구조와 함께 배우는 알고리즘 입문[자바] - 6일차 (0) | 2022.12.08 |
자료구조와 함께 배우는 알고리즘 입문[자바] - 5일차 (0) | 2022.11.21 |
자료구조와 함께 배우는 알고리즘 입문[자바] - 4일차 (0) | 2022.11.16 |