Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e291527

Browse files
[211122] 모의고사
1 parent 507834f commit e291527

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public static int[] solution(int[] answers) {
5+
int[] answer;
6+
7+
int[] a = new int[] { 1, 2, 3, 4, 5 };
8+
int[] b = new int[] { 2, 1, 2, 3, 2, 4, 2, 5 };
9+
int[] c = new int[] { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 };
10+
11+
int[] score = new int[3];
12+
13+
// score[]에 수포자별 맞힌 갯수
14+
for (int i = 0; i < answers.length; i++) {
15+
if (answers[i] == a[i % 5])
16+
score[0]++;
17+
if (answers[i] == b[i % 8])
18+
score[1]++;
19+
if (answers[i] == c[i % 10])
20+
score[2]++;
21+
}
22+
23+
// 가장 높은 점수
24+
int max = 0;
25+
for (int i = 0; i < 3; i++) {
26+
if (score[i] > max) {
27+
max = score[i];
28+
}
29+
}
30+
31+
// 가장 높은 점수를 받은 사람 수
32+
int maxCount = 0;
33+
for (int i = 0; i < 3; i++) {
34+
if (score[i] == max) {
35+
maxCount++;
36+
}
37+
}
38+
39+
answer = new int[maxCount];
40+
int idx = 0;
41+
for (int i = 0; i < 3; i++) {
42+
if (score[i] == max)
43+
answer[idx++] = i + 1;
44+
}
45+
return answer;
46+
}
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /