SWEA

[SWEA] 최빈수 구하기

itsnot4me 2024. 10. 10. 17:15

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=3

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

import java.util.Scanner;
import java.io.FileInputStream;


class Solution
{
	public static void main(String args[]) throws Exception
	{
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
	
		for(int test_case = 1; test_case <= T; test_case++)
		{
            int c = sc.nextInt();
			int[] arr = new int[101];
            for(int i=0; i<1000; i++){                
                int N= sc.nextInt();
                arr[N]++;
            }
            int max = 0;
            int index =0;
            int j;
            for(j=0; j<=100; j++){
                if(max<=arr[j]){
                    max=arr[j];
                    index=j;
                }
		                    
            }
			System.out.println("#" + c + " "+ index);
		}
	}
}

 

* 입력값에 매 테스트케이스 번호가 있어서 혼란을 줌(고려 안하고 풀면 1문제 틀리게 됨)