본문 바로가기
알고리즘 일기

swea_d2_1204_최빈수구하기

by Beijing_KingGod 2020. 1. 20.

1) 가장 많이 나온 점수 를 출력한다.

package algo;

import java.io.*;
import java.util.*;

public class Solution_d2_1204_최빈수구하기 {
	public static void main(String args[]) throws Exception
	{
		System.setIn(new FileInputStream("res/input_1204.txt"));

		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();

		for(int tc = 1; tc <= T; tc++)
		{
			sc.nextInt();
			int[] score = new int[101];
			for(int i=0; i<1000; i++) {
				score[sc.nextInt()]++;
			}
			int max = 0;
			int ans = 0;
			for(int i=0; i<=100; i++) {
				if(score[i]>=max) { // 최빈수가 여러개일 경우 가장 큰수 출력
					max = score[i];
					ans = i;
				}
			}
			System.out.println("#"+tc+" "+ans);
		}
	}
}

'알고리즘 일기' 카테고리의 다른 글

swea_d1_2063_중간값찾기  (0) 2020.01.20
swea_d3_3307_최장증가부분수열  (0) 2020.01.20
프로그래머스 탬플릿  (0) 2019.12.17
c++ map 사용법  (0) 2019.12.10
프로그래머스 : 저울  (0) 2019.12.10

댓글