넘나 오랜만의 포스팅...

좀 여러가지 사정이 있었는데 어쨌든 제대로 못 올린 건 내 잘못 ㅠㅠ....

이제 다시 꾸준히 올려야겠당....

 

 

 

☞ 문제

 

 

 

☞ 코드

 

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
package algo01;
 
 
public class mockTest {
    
    public static void main(String[] args) {
        
        int[] answers = {13242};
        solution(answers);
    }
    
    
    public static int[] solution(int[] answers) {
    
        int[] one = {12345};                    //1번 수포자의 답
        int[] two = {21232425};            //2번 수포자의 답
        int[] three = {3311224455};    //3번 수포자의 답
        int cnt1 = 0;            //1번 수포자가 맞혔을 때 증가하는 변수
        int cnt2 = 0;            //2번 수포자가 맞혔을 때 증가하는 변수
        int cnt3 = 0;            //3번 수포자가 맞혔을 때 증가하는 변수
        
 
        //입력한 숫자와 세 수포자의 답 비교한 후 변수 증가
        for(int i = 0; i < answers.length; i++) {
            if(answers[i] == one[i%one.length]) {
                cnt1++;
            }
            if(answers[i] == two[i%two.length]) {
                cnt2++;
            }
            if(answers[i] == three[i%three.length]) {
                cnt3++;
            }
        }
        
       
        int[] cntNum = {cnt1, cnt2, cnt3};
        Arrays.sort(cntNum);
        
//세 수포자 중 가장 많이 맞힌 문제의 갯수 (cnt1 / cnt2 / cnt3 중 가장 높은 숫자)
        int max = cntNum[2];
        
        List<Integer> maxList = new ArrayList<>();
        if(cnt1 == max) {
            maxList.add(1);
        } 
        if(cnt2 == max) {
            maxList.add(2);
        } 
        if(cnt3 == max) {
            maxList.add(3);
        }
        
        int[] answer = new int[maxList.size()];
        int i = 0;
        for(int temp : maxList) {
            answer[i++= temp;
            System.out.println("answer = " + temp);
        }  
        
        return answer;
    }
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
 

 

 

 

☞ 실행결과

 

 

'Algorithm' 카테고리의 다른 글

124 나라의 숫자  (0) 2019.05.27
예산  (1) 2019.05.03
콜라츠 추측  (0) 2019.04.28
시저 암호  (1) 2019.04.25
나누어 떨어지는 숫자 배열  (2) 2019.04.22

+ Recent posts