[SWEA 1204] 최빈값 구하기 JAVA

LeeJ·2023년 1월 5일
0

SWEA

목록 보기
2/5
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 test_case = 1; test_case <= T; test_case++)
		{
			int n = sc.nextInt();
			int max = 0;
			int index = 0;
			int[] arr = new int[101];
			
			for (int i = 0; i < 1000; i++) {
				arr[sc.nextInt()]++;
			}
			
			for (int i = 0; i<arr.length; i++) {
				if(arr[i]>=max) {
					max = arr[i];
					index = i;
				}
			}
			
			System.out.println("#" + n + " " + index);
		}
	}
}
profile
헤응

0개의 댓글

관련 채용 정보