https://swexpertacademy.com/main/main.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
SWEA 1204번
1000명의 학생의 점수를 입력 받아 점수 중 최빈수를 구하는 문제
점수는 0~100점이기 때문에 101 사이즈의 배열을 만들어서 해당 점수 값을 증가시킴
import java.util.Scanner;
public class P1204 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=1; t<=T; t++){
int n = sc.nextInt();
int[] a = new int[101];
int max = 0, ans = 0;
for(int i=0; i<1000; i++){
int k = sc.nextInt();
a[k]++;
}
for(int i=0; i<a.length; i++){
if(max <= a[i]) { // 최빈수가 여러 개일 경우 가장 큰 점수
max = a[i];
ans = i;
}
}
System.out.println("#"+n+" "+ans);
}
}
}
'알고리즘 > SWEA' 카테고리의 다른 글
[SWEA] 1244. [S/W 문제해결 응용] 2일차 - 최대 상금 (0) | 2022.11.09 |
---|---|
[SWEA] 1974. 스도쿠 검증 (0) | 2022.11.08 |
[SWEA] 1961. 숫자 배열 회전 (0) | 2022.11.08 |
[SWEA] 1954. 달팽이 숫자 (0) | 2022.11.07 |
[SWEA] 1928. Base64 Decoder (0) | 2022.11.07 |