PS
[SWEA] 1204 최빈수 구하기
Eastplanet
2024. 1. 11. 09:14
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
/**
* 0. 입력파일 읽어들이기
*/
//기본 입력 설정
System.setIn(new FileInputStream("1204_input.txt"));
//파일에 있는 내용이 인풋스트림리더와 버퍼드리더를 통해서 오게됨
//인풋 스트림 리더 : 1바이트가 아닌 2바이트 씩 읽음 -> 텍스트 문서를 빠르게 읽기 위해
//버퍼드 리더 : 인풋 스트림 리더로 100바이트를 가져오려면 50번이나 들고오지만 100바이트 짜리 버퍼를 이용하여 버퍼를 채운 뒤 한번에 받음
//50번 들고오는 방식은 파일 입출력 시간이 오래 걸림
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//결과를 한번에 출력하기 위한 StringBuilder
//버퍼 사용
StringBuilder sb = new StringBuilder();
int T;
T = Integer.parseInt(in.readLine());
for(int test_case = 1; test_case <= T ; test_case++) {
int tc = Integer.parseInt(in.readLine());
sb.append("#"+test_case+" ");
int []arr = new int[1001];
int []count = new int[101];
String[] split = in.readLine().split(" ");
for(String score: split) {
int val = Integer.parseInt(score);
count[val]++;
}
int maxIdx = 0;
for(int i=0;i<=100;i++) {
if(count[maxIdx]<=count[i]) {
maxIdx = i;
}
}
sb.append(maxIdx+"\n");
}
System.out.println(sb);
}
}