[D2] 1204 - 최빈수 구하기알고리즘/SWEA2023. 8. 14. 19:26
Table of Contents
최빈수는 가장 여러 번 나타나는 값을 의미
package SWEA;
import java.util.Scanner;
public class Solution1204 {
public static void main(String[] args) {
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[] arr = new int[101]; //학생들의 0~100점까지의 범위
for(int i=0; i<1000;i++) { //학생들의 점수를 1000명만큼 입력
arr[sc.nextInt()]++; //해당하는 점수에 index값을 +1증가시킴
}
int max = 0;
int index = 0;
for(int i=0; i<arr.length; i++) {
if(arr[i] >= max) {
max = arr[i];
index = i; //인덱스 최빈값 반환.
}
}
System.out.println("#" + n + " " + index);
}
}
728x90
'알고리즘 > SWEA' 카테고리의 다른 글
[D2] 1288 - 새로운 불면증 치료법 (0) | 2023.08.14 |
---|---|
[D2] 1284 - 수도 요금 경쟁 (0) | 2023.08.14 |
[D1] 2056 - 연월일 달력 (0) | 2023.08.12 |
[D1] 2058 - 자릿수 더하기 (0) | 2023.08.12 |
[D1] 2063 - 중간값 찾기 (0) | 2023.08.12 |
@leegeonwoo :: geonwoo
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!