티스토리 뷰

반응형


1204. 최빈수 구하기

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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Solution1204 {
    public void run() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        
        for(int i=0; i<T; i++) {    // 테스트 케이스 수
            int n = Integer.parseInt(br.readLine());
            StringTokenizer st = new StringTokenizer(br.readLine());
            
            int[] score_arr = new int[101];        // score 배열
            
            while (st.hasMoreTokens()) {
                int tmp = Integer.parseInt(st.nextToken());
                score_arr[tmp]++;
            }
            
            int max = 0;    // 빈도수
            int max_idx = 0;    // 최빈수
            int sc_ar_idx = 0;    // array index
 
            for(int sc : score_arr) {
                if(sc > max) {
                    max = sc;
                    max_idx = sc_ar_idx;
                } 
                if(sc == max) {
                    if (sc_ar_idx > max_idx) {
                        max_idx = sc_ar_idx;
                    }
                }
                sc_ar_idx++;
            }
 
            System.out.println("#" + (i+1+ " " + max_idx);
        }
    }
    
    public static void main(String[] args) throws Exception {
        new Solution1204().run();
    }
}
cs


--

10

1

41 85 72 38 80 69 65 68 96 22 49 67 51 61 63 87 66 24 80 83 71 60 64 52 90 60 49 31 23 99 94 11 25 24 51 15 13 39 67 97 19 76 12 33 99 18 92 35 74 0 95 71 39 33 39 32 37 45 57 71 95 5 71 24 86 8 51 54 74 24 75 70 33 63 29 99 58 94 52 13 35 99 46 57 71 23 17 3 94 48 77 18 83 11 83 25 59 62 2 78 86 7 94 65 80 32 39 84 60 65 72 61 58 84 8 72 12 19 47 49 49 59 71 52 34 22 21 20 92 33 80 39 74 9 28 97 100 93 29 25 4 66 79 81 98 21 91 62 82 4 59 100 34 1 51 80 92 69 77 39 38 97 51 34 35 19 22 1 67 9 90 31 82 11 51 84 78 70 74 42 100 88 53 80 57 62 32 51 48 63 92 46 4 61 31 98 69 52 88 20 68 41 48 79 97 98 56 44 73 3 63 100 87 87 41 79 64 83 63 1 21 72 24 9 75 51 25 53 77 0 52 30 96 93 32 89 70 89 55 71 79 40 10 64 80 30 19 62 67 98 42 8 32 57 27 22 1 38 89 52 74 43 8 2 65 82 20 67 22 43 22 95 16 48 25 6 75 86 96 3 85 43 69 93 4 61 53 81 43 84 20 15 34 22 35 26 28 33 67 19 79 19 45 8 13 51 0 86 68 18 47 82 3 16 80 0 18 39 22 5 26 65 70 21 92 66 65 14 6 46 46 21 32 ....


--

#1 71

#2 76

#3 79

#4 80

#5 52

#6 66

#7 35

#8 97

#9 92

#10 72




반응형
댓글
최근에 올라온 글
최근에 달린 댓글
링크
Total
Today
Yesterday