-
Programmers LV.1 모의고사Programmers 2020. 12. 30. 00:32
왜 자꾸 안되지 하다가 다시보니,
수포자의 답이 5/8/10 으로 나뉘어 계속적으로 반복한다는걸 뒤늦게 확인함
@org.junit.Test public void supoja(){ int[] answers = {4,1,2,3,4,4,1,2,3,4,4,1,2,3,4,4,1,2,3,4}; /*int[] answers = {1,2,3,4,5};*/ int[][] giveup = {{1, 2, 3, 4, 5},{2, 1, 2, 3, 2, 4, 2, 5},{3, 3, 1, 1, 2, 2, 4, 4, 5, 5}}; Map<Integer,Integer> giveUpPeple = new HashMap<>(); List<Integer> pepleList = new ArrayList<>(); int pepleCnt = 1; for(int[] giveUpValue : giveup){ int cnt = 0; int j = 0; for(int i=0; i<answers.length; i++){ if(pepleCnt == 1){ j = i % 5 ; }else if(pepleCnt == 2){ j = i % 8 ; }else if(pepleCnt == 3){ j = i % 10 ; } if(answers[i] == giveUpValue[j]){ cnt++; } } giveUpPeple.put(pepleCnt,cnt); pepleList.add(pepleCnt); pepleCnt++; } Collections.sort(pepleList, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return giveUpPeple.get(o2).compareTo(giveUpPeple.get(o1)); } }); int max = giveUpPeple.get(pepleList.get(0)); List<Integer> answerList = new ArrayList<>(); for(Integer id : pepleList){ int value = giveUpPeple.get(id); if(max <= value){ if(max == value){ answerList.add(id); }else{ max =value; } } } int[] answer = new int[answerList.size()]; int cnt =0; for(Integer id : answerList){ answer[cnt] = id; System.out.println(id); cnt++; } }
'Programmers' 카테고리의 다른 글
Programmers LV.2 타겟넘버 (0) 2020.12.30 Programmers LV.2 카펫 (0) 2020.12.30 Programmers LV.2 가장 큰 수 (0) 2020.12.29 Programmers LV.1 K번째수 (0) 2020.12.29 Programmers LV.3 디스크 컨트롤러 (0) 2020.12.29