728x90
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 | static final int STUDENT_NUM = 3; static int[] student1_guessPattern = {1,2,3,4,5}; static int[] student2_guessPattern = {2,1,2,3,2,4,2,5}; static int[] student3_guessPattern = {3,3,1,1,2,2,4,4,5,5}; public int[] solution(int[] answers) { int[] score = getScore(answers); int topScore = getTopScore(score); ArrayList<Integer> fistRankList = getfirstRankList(score,topScore); int[] answer = converIntegers(fistRankList); return answer; } public int[] converIntegers(ArrayList<Integer> arrayList){ int[] array = new int[arrayList.size()]; for(int i=0; i<array.length; i++){ array[i] = arrayList.get(i); } return array; } public ArrayList<Integer> getfirstRankList(int[] score, int topScore){ ArrayList<Integer> firstRankList = new ArrayList<>(); for(int i=0; i<score.length; i++){ if(topScore==score[i]) firstRankList.add(i+1); } return firstRankList; } public int getTopScore(int[] score){ int topScore = 0; for(int i=0; i<score.length; i++){ topScore = Math.max(score[i],topScore); } return topScore; } public int[] getScore(int[] answers){ int[] score = new int[STUDENT_NUM]; for(int problemNum = 0; problemNum < answers.length; problemNum++ ){ if( student1_guessPattern[ problemNum%student1_guessPattern.length ] == answers[problemNum] ) score[0]++; if( student2_guessPattern[ problemNum%student2_guessPattern.length ] == answers[problemNum] ) score[1]++; if( student3_guessPattern[ problemNum%student3_guessPattern.length ] == answers[problemNum] ) score[2]++; } return score; } | cs |
'알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][JAVA] 신규 아이디 추천 (String) (0) | 2021.09.06 |
---|---|
프로그래머스 - 숫자 야구 (완전탐색) (0) | 2019.12.13 |
프로그래머스 - 가장 큰 수 (정렬) (0) | 2019.12.08 |
프로그래머스 - ORACLE SQL (String,Date) (0) | 2019.12.08 |
프로그래머스 - ORACLE SQL (JOIN) (0) | 2019.12.08 |