배운것
- 소수첫째자리 반올림 Math.round()
- 절대값 Math.abs();
- 음수범위를 포함하여 인덱스에 넣을때는 공통된 어떤 수를 더하여 가장 작은 수가 0이 되도록 만들어 주는 것이 편하다
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
|
package 정렬;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
public class 통계학 {
static int[] nums ;
static int[] chk = new int[8001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
nums = new int[n];
double avg = 0;
for (int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(br.readLine());
chk[nums[i]+4000]++;
avg += nums[i];
}
int maxIndex = 0;
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i <8001; i++) {
if(chk[maxIndex]<chk[i]){
maxIndex = i;
list.clear();
}
else if(chk[i]!= 0 &&chk[i] == chk[maxIndex])
{
list.add(i-4000); //두번째 최빈값부터 계속 리스트에 추가
}
}
Arrays.sort(nums);
System.out.println((int)Math.round((double)(avg/n))) ;
System.out.println(nums[n/2]);
if(list.size()!= 0)
System.out.println(list.get(0));
else
System.out.println(maxIndex-4000);
System.out.println(nums[n-1]-nums[0]);
}
}
|
cs |
'IT > 알고리즘' 카테고리의 다른 글
백준 1427 소트인사이드 (1) | 2020.02.16 |
---|---|
백준 11729 하노이탑 이동순서 문제 (0) | 2020.02.15 |
백준2775번 부녀회장이될테야 (0) | 2020.01.10 |
백준 10250 ACM호텔 (0) | 2020.01.10 |
백준2869 달팽이는 올라가고싶다(수학) (2) | 2020.01.04 |