티스토리 뷰

1204. [S/W 문제해결 기본] 1일차 - 최빈수 구하기

swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE&problemTitle=&orderBy=INQUERY_COUNT&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

import java.util.Scanner;

// 210128
// 1204. [S/W 문제해결 기본] 1일차 - 최빈수 구하기

public class SWEA1204 {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 
		
		int T = sc.nextInt();
		for(int tc=0; tc<T; tc++) {
			int TN = sc.nextInt();
			
			int[] arr = new int[101];
			int maxScore = -1;
			int maxCnt = -1;
			for (int stu=0; stu<1000; stu++) {
				int score = sc.nextInt();
				arr[score] += 1;
				if (arr[score] > maxCnt) {
					maxCnt = arr[score];
					maxScore = score;
				} else if (arr[score] == maxCnt) {
					// 최빈수가 여러 개 일 때에는 가장 큰 점수
					if (score >= maxScore) {
						maxScore = score;
						maxCnt = arr[score];
					}
				}
			} // for
			System.out.println("#" + TN + " " + maxScore);
			
		}
		
		sc.close();
	} // main

}

 

'코딩테스트 > SW Expert' 카테고리의 다른 글

[SWEA] 1954. 달팽이 숫자  (0) 2021.01.30
[SWEA] 2007. 패턴 마디의 길이  (0) 2021.01.29
[SWEA] 1926. 간단한 369게임  (0) 2021.01.29
[SWEA] 1859. 백만 장자 프로젝트  (0) 2021.01.28
[SWEA] 1974. 스도쿠 검증  (0) 2021.01.21
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함