Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 코테
- 문제풀이
- db
- SQL
- binary search
- SWEA
- oracle
- 자바
- 백준
- 러닝일지
- math
- greedy
- 운동기록
- 코딩테스트
- MySQL
- DP
- 알고리즘
- 문자열
- Java
- 문제해결
- 투포인터
- priorityqueue
- 프로그래머스
- COS PRO
- 건강
- BFS
- dfs
- BOJ
- 이분탐색
- 시뮬레이션
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.1 모의 고사 본문

[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/42840
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
static class Exam{
int num,score;
Exam(int num,int score){
this.num = num;
this.score = score;
}
}
public int[] solution(int[] answers) {
int n = answers.length;
Exam[] exams = new Exam[3];
for(int i=0;i<3;i++){
exams[i] = new Exam(i+1,0);
}
int[] math1 = {1,2,3,4,5};
int[] math2 = {2,1,2,3,2,4,2,5};
int[] math3 = {3,3,1,1,2,2,4,4,5,5};
for(int i=0;i<n;i++){
if(math1[i%5]==answers[i]) exams[0].score++;
if(math2[i%8]==answers[i]) exams[1].score++;
if(math3[i%10]==answers[i]) exams[2].score++;
}
List<Integer> list = new ArrayList<>();
int maxScore = Math.max(Math.max(exams[0].score,exams[1].score),exams[2].score);
for(int i=0;i<3;i++){
if(maxScore==exams[i].score) list.add(exams[i].num);
}
Collections.sort(list);
int[] answer = new int[list.size()];
for(int i=0;i<list.size();i++){
answer[i] = list.get(i);
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.1 예산 (0) | 2025.10.09 |
|---|---|
| [프로그래머스] Lv.1 체육복 (0) | 2025.10.09 |
| [프로그래머스] Lv.2 소수 찾기 (0) | 2025.10.09 |
| [프로그래머스] Lv.2 가장 큰 수 (0) | 2025.10.08 |
| [프로그래머스] Lv.1 K번째수 (0) | 2025.10.08 |