Algorithm/SWEA

[swexpert] 1204. 최빈수 구하기

반응형

[swexpert] 1204. 최빈수 구하기


문제 링크


https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
 
public class Solution_1204 {
 
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        
        int ts = s.nextInt();
        
        
        for (int i = 0; i < ts; i++) {
            
            int maxCnt = 0// 최다 카운트 저장 변수
            int maxScore = 0// 최고 점수 저장 변수
            
            int[] students = new int[1000]; //학생 수 저장 배열
            int[] scoreCnt = new int[101]; // 스코어 카운트 저장 배열
            
            int tsNum = s.nextInt();
            
            for (int j = 0; j < students.length; j++) { // 스코어 카운트에 학생들 점수별 수 저장
                int score = s.nextInt();
                scoreCnt[score]++;
            }
            
            
            for (int z = 0; z < scoreCnt.length; z++) { // 최다 카운트 저장
                if(maxCnt <= scoreCnt[z]) maxCnt = scoreCnt[z];
            }
            
            int tmp = 0;
            
            for (int z = 0; z < scoreCnt.length; z++) {
                
                if(scoreCnt[z] == maxCnt) { // 최다 카운트를 통해 최고 점수를 확인
                    if(tmp <= z){
                        tmp = z;
                        maxScore = tmp;
                    }
                }
            }
            
            
            System.out.println("#"+ tsNum + " " + maxScore);
        }
    }
 
}
cs


반응형

'Algorithm > SWEA' 카테고리의 다른 글

[swexpert] 1225. 암호생성기  (0) 2019.01.11
[swexpert] 1206. View  (0) 2019.01.11
[swexpert] 5431. 민석이의과제체크하기  (0) 2019.01.08
[swexpert] 1208. Flatten  (0) 2019.01.08
[swexpert] 2063. 중간값 찾기  (0) 2019.01.07