You will be fine

<Algorithm> 102. 모의고사(프로그래머스)

by BFine
반응형

1. 모의고사(프로그래머스)

  • 문제해결능력 문제 

  • List를 어떻게 배열로 바꿀지 고민했는데 다른사람 코드보니 mapToInt와 toArray를 사용한 것을 보고 따라서 출력부분만 바꿔보았다.

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
import java.util.LinkedList;
import java.util.List;
import java.util.stream.IntStream;
 
public class Solution {
      static int[] ans_peo = new int [3];
      public int[] solution(int[] answers) {
            int[][] people = {
                    {},
                    {12345},
                    {21232425},
                    {3311224455}
                                                    };
            /******************************
             * 문제답과 찍는 방식을 완전탐색으로
             * 비교하여 최대치를 구하고 
             * 최대치와 같은 사람을 출력한다
             *******************************/
            
            IntStream.range(0, answers.length)
                     .forEach(i->{
                         if(answers[i] == people[1][i%5]) {
                             ans_peo[0]++;
                         }
                         if(answers[i] == people[2][i%8]) {
                             ans_peo[1]++;
                         }
                         if(answers[i] == people[3][i%10]) {
                             ans_peo[2]++;
                         }
                     });
             
            List<Integer> list = new LinkedList<>();
            int max = IntStream.of(ans_peo).max().getAsInt();
            
            IntStream.range(03).filter(i->ans_peo[i]==max).forEach(i->list.add(i+1));
               
           return list.stream().mapToInt(i->i).toArray();
        }
}
 
cs


참고 & 출처  




반응형

블로그의 정보

57개월 BackEnd

BFine

활동하기