[SWEA] #1204 최빈수 구하기

KwonSC·2021년 11월 6일
0

SWEA - Java

목록 보기
1/26
post-thumbnail

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE


Code

import java.util.Scanner;

class Solution {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int testCase = 1; testCase <= T; testCase++) {
            int t = sc.nextInt();
            int[] arr = new int[101];
            for (int i = 0; i < 1000; i++) {
                int temp = sc.nextInt();
                arr[temp]++;
            }
            int max = 0;
            int result = 0;
            for (int i = 0; i < 101; i++) {
                if (max <= arr[i]) {
                    max = arr[i];
                    result = i;
                }
            }
            System.out.printf("#%d %d\n", t, result);
        }
    }
}

Solution

크기 101의 배열 arr를 선언해 각 점수대의 인원수를 체크하고 arr의 최대값 인덱스를 출력한다.

0개의 댓글