Lined Notebook

[6958] [Java] 동철이의 프로그래밍 대회

by HeshAlgo

<동철이의 프로그래밍 대회>

문제 설명

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

 

내 생각

1등이 푼 문제의 수가 최대 몇개인지 먼저 체크하기로 했다. 이 후, 1등이 푼 문제의 수가 같은 사람이 몇명인지 한번더 반복문을 돌려서 몇명인지 확인했습니다. 다른사람들의 코드에 비해 좀 긴편이라 줄일 수 있도록 해야겠습니다.

 

푼 시간

20분 34초

 

작성 코드

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
50
51
52
53
54
55
56
57
58
59
import java.io.FileInputStream;
import java.util.*;
 
public class E6958 {
 
    public static void main(String args[]) throws Exception {
        String path = "s_input.txt";
        System.setIn(new FileInputStream(path));
        List<Integer> list = new ArrayList<Integer>(); 
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();
    
        for(int test_case = 1; test_case <= T; test_case++) {
            int N = sc.nextInt();    // 사람 수
            int M = sc.nextInt();    // 문제 수
            int[][] problem = new int[N][M];
            
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    problem[i][j] = sc.nextInt();
                }
            }
            
            int problemCount = 0;
            
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    if (problem[i][j] == 1) {
                        problemCount++;
                    }
                }
                list.add(problemCount);
                problemCount = 0;    
            }
            
            int first = 0;
            for (int i = 0; i < list.size(); i++) {
                if (first < list.get(i)) {
                    first = list.get(i);
                }
            }
            
            int peopleCount = 0;
            for (int i = 0; i < list.size(); i++) {
                if (first == list.get(i)) {
                    peopleCount++;
                }
            }
            
            System.out.println("#" + test_case + " " + peopleCount + " " + first);
            
            list.clear();
        }
        
        
    }
    
}
 
 

 

실행 결과

블로그의 정보

꾸준히 공부하는 개발 노트

HeshAlgo

활동하기