https://school.programmers.co.kr/learn/courses/30/lessons/42840
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
int[] supoza1 = {1, 2, 3, 4, 5};
int[] supoza2 = {2, 1, 2, 3, 2, 4, 2, 5};
int[] supoza3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
int[] score = new int[3];
int a = 1;
int temp = 0;
for (int k : answers) { // ์ํฌ์1 ์ ์ ๊ตฌํ๊ธฐ
if (supoza1[temp] == k) {
score[0] += a;
}
temp++;
if (temp == 5) {
temp = 0;
}
}
temp = 0;
for (int k : answers) { // ์ํฌ์2 ์ ์ ๊ตฌํ๊ธฐ
if (supoza2[temp] == k) {
score[1] += a;
}
temp++;
if (temp == 8) {
temp = 0;
}
}
temp = 0;
for (int k : answers) { // ์ํฌ์3 ์ ์ ๊ตฌํ๊ธฐ
if (supoza3[temp] == k) {
score[2] += a;
}
temp++;
if (temp == 10) {
temp = 0;
}
}
int max = score[0];
int high = 0;
for (int j : score) { // ์ต๋ ์ ์ ๊ตฌํ๊ธฐ
if (max < j) {
max = j;
}
}
for (int j : score) { // ๊ฐ์ฅ ๋ฌธ์ ๋ฅผ ๋ง์ด ๋งํ ์ฌ๋์ด ๋ช ๋ช
์ธ์ง ๊ตฌํ๊ธฐ
if (j == max) {
high++;
}
}
int[] answer = new int[high];
int index = 0;
for (int i = 0; i < score.length; i++) { // ๋ฐฐ์ด์ ์ธ๋ฑ์ค ์ฑ์ฐ๊ธฐ
if (score[i] == max) {
answer[index] = i + 1;
index++;
}
}
Arrays.sort(answer); // ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
return answer;
}
}