티스토리 뷰

프로그래머스 모의고사 - https://programmers.co.kr/learn/courses/30/lessons/42840


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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
int[][] people = new int[answers.length][3]; // 이중배열로 길이와 3개를 넣을수 있는 배열 선언
        /**
         * 수포자 2의 경우 (i+1)%8 나머지로 계산가능
         * 수포자 3의 경우 (i+1)%10 나머지로 계산가능
         */
        int people1Atari = 0;
        int people2Atari = 0;
        int people3Atari = 0;
 
        int count1 = 1;
        for (int i = 0; i < answers.length; i++) {
            // 수포자1
            people[i][0= count1;
            count1++;
            if (count1 == 6) count1 = 1;
 
            //수포자 2
            int temp = (i + 1) % 8;
 
            switch (temp) {
                case 1:
                    temp = 2;
                    break;
                case 2:
                    temp = 1;
                    break;
                case 3:
                    temp = 2;
                    break;
                case 4:
                    temp = 3;
                    break;
                case 5:
                    temp = 2;
                    break;
                case 6:
                    temp = 4;
                    break;
                case 7:
                    temp = 2;
                    break;
                case 0:
                    temp = 5;
                    break;
            }
            people[i][1= temp;
            //수포자 3
            temp = (i + 1) % 10;
            switch (temp) {
                case 1:
                    temp = 3;
                    break;
                case 2:
                    temp = 3;
                    break;
                case 3:
                    temp = 1;
                    break;
                case 4:
                    temp = 1;
                    break;
                case 5:
                    temp = 2;
                    break;
                case 6:
                    temp = 2;
                    break;
                case 7:
                    temp = 4;
                    break;
                case 8:
                    temp = 4;
                    break;
                case 9:
                    temp = 5;
                    break;
                case 0:
                    temp = 5;
                    break;
            }
            people[i][2= temp;
 
            //정답문해
 
            if (answers[i] == people[i][0]) {
                people1Atari++;
            }
            if (answers[i] == people[i][1]) {
                people2Atari++;
            }
            if (answers[i] == people[i][2]) {
                people3Atari++;
            }
        }
        int max = Math.max(people1Atari, Math.max(people2Atari, people3Atari));
        int[] hit = new int[3];
        hit[0= people1Atari;
        hit[1= people2Atari;
        hit[2= people3Atari;
        ArrayList<Integer> alist = new ArrayList<>();
        //순서 넣기
        for (int i = 0; i < 3; i++) {
            if (max == hit[i]) alist.add(i + 1);
        }
        //답안제출
        int[] answer = new int[alist.size()];
        for (int i = 0; i < 3; i++) {
            answer[i] = alist.get(i);
        }
 
        return answer;
cs



공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
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
글 보관함