Skip to content

Commit 7df7e31

Browse files
committed
[level 1] Title: 모의고사, Time: 33.26 ms, Memory: 36.9 MB -BaekjoonHub
1 parent 95a5bce commit 7df7e31

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [level 1] 모의고사 - 42840
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/42840)
4+
5+
### 성능 요약
6+
7+
메모리: 36.9 MB, 시간: 33.26 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 완전탐색
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 05일 15:13:04
20+
21+
### 문제 설명
22+
23+
<p>수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다.</p>
24+
25+
<p>1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...<br>
26+
2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...<br>
27+
3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...</p>
28+
29+
<p>1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요.</p>
30+
31+
<h5>제한 조건</h5>
32+
33+
<ul>
34+
<li>시험은 최대 10,000 문제로 구성되어있습니다.</li>
35+
<li>문제의 정답은 1, 2, 3, 4, 5중 하나입니다.</li>
36+
<li>가장 높은 점수를 받은 사람이 여럿일 경우, return하는 값을 오름차순 정렬해주세요.</li>
37+
</ul>
38+
39+
<h5>입출력 예</h5>
40+
<table class="table">
41+
<thead><tr>
42+
<th>answers</th>
43+
<th>return</th>
44+
</tr>
45+
</thead>
46+
<tbody><tr>
47+
<td>[1,2,3,4,5]</td>
48+
<td>[1]</td>
49+
</tr>
50+
<tr>
51+
<td>[1,3,2,4,2]</td>
52+
<td>[1,2,3]</td>
53+
</tr>
54+
</tbody>
55+
</table>
56+
<h5>입출력 예 설명</h5>
57+
58+
<p>입출력 예 #1</p>
59+
60+
<ul>
61+
<li>수포자 1은 모든 문제를 맞혔습니다.</li>
62+
<li>수포자 2는 모든 문제를 틀렸습니다.</li>
63+
<li>수포자 3은 모든 문제를 틀렸습니다.</li>
64+
</ul>
65+
66+
<p>따라서 가장 문제를 많이 맞힌 사람은 수포자 1입니다.</p>
67+
68+
<p>입출력 예 #2</p>
69+
70+
<ul>
71+
<li>모든 사람이 2문제씩을 맞췄습니다.</li>
72+
</ul>
73+
74+
75+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(answers) {
2+
const answer = [];
3+
4+
//찍는 방식
5+
const p1 = [1, 2, 3, 4, 5];
6+
const p2 = [2, 1, 2, 3, 2, 4, 2, 5];
7+
const p3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
8+
9+
const scores = [0, 0, 0];
10+
11+
for (let i = 0; i < answers.length; i++) {
12+
if (answers[i] === p1[i % p1.length]) scores[0]++;
13+
if (answers[i] === p2[i % p2.length]) scores[1]++;
14+
if (answers[i] === p3[i % p3.length]) scores[2]++;
15+
}
16+
17+
const max = Math.max(...scores);
18+
19+
if (scores[0] === max) answer.push(1);
20+
if (scores[1] === max) answer.push(2);
21+
if (scores[2] === max) answer.push(3);
22+
23+
return answer;
24+
}

0 commit comments

Comments
 (0)