Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- jenkins
- 20055
- CMD
- 알고리즘
- 백준
- Java
- Error
- 이산수학
- documentationpluginsbootstrapper
- 2108_통계학
- 투에모스문자열
- Error fetching remote repo 'origin'
- SpringBoot
- 이클립스
- 18222
- Eclipse
- to display the conditions report re-run your application with 'debug' enabled
- 2167. 2차원 배열의 합
- 자바
- 프로그래머스
- 14466
- 호석이두마리치킨
- 별자리 만들기
- 날짜일수
- 설정
- dockercompose
- 소가길을건너간이유6
- EC2
- docker
- 21278
Archives
- Today
- Total
계단을 오르듯이
백준 [JAVA] 2108. 통계학 본문
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
45
46
|
package algo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class B_2108_통계학 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(in.readLine());
int[] arr = new int[N];
int sum = 0; // 산술 평균을 위한 총합
int centerIdx = N / 2; // 중앙값을 위한 인덱스
int[] cntt = new int[8001]; // 최빈값
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(in.readLine());
sum += arr[i];
cntt[arr[i] + 4000]++;
}
Arrays.sort(arr);
sb.append((int) Math.round((double) sum / N) + "\n"); // 반올림을 위해 double과 int형변환
sb.append(arr[centerIdx] + "\n");
boolean flag = true; // 두번째로 작은 값을 위해
int mm = 0, num = 0;
for (int i = 0; i < 8001; i++) {
if (cntt[i] == 0) // 중요
continue;
if (mm < cntt[i]) {
mm = cntt[i];
num = i - 4000;
flag = true; // ** 다시 새로운 값으로 갱신되면 그 수와 같은 2번째 작은 수를 구해야 하므로!!
} else if (mm == cntt[i] && flag) {
flag = false;
num = i - 4000;
}
}
sb.append(num + "\n");
sb.append(arr[N - 1] - arr[0] + "\n"); // 범위
System.out.println(sb);
}
}
|
cs |
'알고리즘 > 백준_JAVA' 카테고리의 다른 글
백준 [JAVA] 2167. 2차원 배열의 합 (0) | 2022.03.01 |
---|---|
백준[JAVA] 1003. 피보나치함수 (0) | 2022.02.24 |
백준 [JAVA] 5430. AC (0) | 2022.02.23 |
[JAVA] 11403. 경로 찾기 (0) | 2022.02.06 |
[JAVA] 2638. 치즈 (0) | 2022.02.06 |