일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스
- c
- 파이썬
- 스포티파이
- CS
- Spring JPA
- programmers
- Spring
- SWEA
- modern c++
- regression
- Gem
- 백준
- 회귀
- 회원가입
- C++
- java
- spring boot
- Baekjoon
- spotify
- Bitget
- SW Expert Academy
- Computer Science
- Spotify Api
- SECS
- SECS-II
- python
- 자바
- 비트겟
- SECS/GEM
Archives
- Today
- Total
비버놀로지
[Programmers 프로그래머스] 42840 모의고사 본문
728x90
programmers.co.kr/learn/courses/30/lessons/42840
코딩테스트 연습 - 모의고사
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는
programmers.co.kr
수포자들의 번호를 찍는 방식을 입력해 준후, 길이가 넘어가면 처음부터 다시 찍도록 만들어 준다.
그후 맞춘갯수가 최대인 값을 구하고, 이와 같은 수포자를 배열에 담아준다.
import java.util.ArrayList;
import java.util.Arrays;
class Solution {
public int[] solution(int[] answers) {
int a[]={1,2,3,4,5}; //1번 수포자가 찍는 방식
int b[]={2,1,2,3,2,4,2,5}; //2번 수포자가 찍는 방식
int c[]={3,3,1,1,2,2,4,4,5,5}; //3번 수포자가 찍는 방식
int answer[];
int temp[]=new int[4];
for (int i = 0; i < answers.length; i++) {
if(a[i%a.length]==answers[i]) { //길이가 넘어갈때 다시 앞으로
temp[1]++;
}
if(b[i%b.length]==answers[i]) { //길이가 넘어갈때 다시 앞으로
temp[2]++;
}
if(c[i%c.length]==answers[i]) { //길이가 넘어갈때 다시 앞으로
temp[3]++;
}
}
int num=0;
for (int i = 0; i < temp.length; i++) { //최대값을 찾기
if(temp[i]>num) {
num=temp[i];
}
}
ArrayList<Integer> que=new ArrayList<Integer>(); //최대값이 여러개일 경우 넣어줄 리스트
for (int i = 0; i < temp.length; i++) { //최대값과 같은 값을 리스트에 넣어준다.
if(temp[i]==num) {
que.add(i);
}
}
answer=new int[que.size()];
for (int i = 0; i < answer.length; i++) { //리스트에 있는 값을 배열로 만들어 준다.
answer[i]=que.get(i);
}
Arrays.sort(answer);
return answer;
}
}
728x90
'ALGORITM > JAVA' 카테고리의 다른 글
[Programmers 프로그래머스] 42748 K번째수 (0) | 2021.01.07 |
---|---|
[Programmers 프로그래머스] 42862 체육복 (0) | 2021.01.07 |
[Programmers 프로그래머스] 42576 완주하지 못한 선수 (0) | 2021.01.06 |
[Programmers 프로그래머스] 68644 두 개 뽑아서 더하기 (JAVA) (0) | 2021.01.06 |
[Programmers 프로그래머스] 64061 크레인 인형뽑기 게임 (0) | 2021.01.06 |
Comments