일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 스프링부트 #springboot #project #Intellij
- Tomcat #SpringFramework
- restapi
- Oracle11g
- IntelliJ
- Database
- mysql
- Web
- SpringInitializer
- RESTful
- development
- HATEOAS
- undefined
- apache
- tcping
- 스프링부트
- mssql
- 웹개발
- install
- oracle
- Developer
- SpringSecurity
- springboot
- ojdbc
- 스프링시큐리티
- 환경변수
- Maven
- postman
- sqldeveloper
- springboot #controller #jsp
Archives
- Today
- Total
여백에 도장 찍기
[프로그래머스/Level2/완전탐색/모의고사] 본문
https://programmers.co.kr/learn/courses/30/lessons/42840
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
class Solution {
public int[] solution(int[] answers) {
int[] answer = {};
int a = answers.length; // 문항 갯수
int[] supoja1_pattern = {1,2,3,4,5}; // 5
int[] supoja2_pattern = {2,1,2,3,2,4,2,5}; // 8
int[] supoja3_pattern = {3,3,1,1,2,2,4,4,5,5}; // 10
int[] supoja1_dapji = new int[answers.length];
int[] supoja2_dapji = new int[answers.length];
int[] supoja3_dapji = new int[answers.length];
int supoja1_jumsu = 0;
int supoja2_jumsu = 0;
int supoja3_jumsu = 0;
// 각각의 배열에 답지를 생성한다.
for(int i=0; i<answers.length; i++){
supoja1_dapji[i] = supoja1_pattern[i%5];
supoja2_dapji[i] = supoja2_pattern[i%8];
supoja3_dapji[i] = supoja3_pattern[i%10];
if(supoja1_dapji[i] == answers[i]){
supoja1_jumsu += 1;
}
if(supoja2_dapji[i] == answers[i]){
supoja2_jumsu += 1;
}
if(supoja3_dapji[i] == answers[i]){
supoja3_jumsu += 1;
}
}
HashMap<Integer, Integer> aa = new HashMap<>();
aa.put(1, supoja1_jumsu);
aa.put(2, supoja2_jumsu);
aa.put(3, supoja3_jumsu);
ArrayList<Integer> list = new ArrayList<>();
int max = -1;
for (int i=1; i<4; i++){
if(aa.get(i) >= max){
max = aa.get(i);
}
}
for(int i=1; i<4; i++){
if(aa.get(i) == max){
list.add(i);
}
}
answer = new int[list.size()];
int size = 0;
for(int l : list){
answer[size++] = l;
}
Arrays.sort(answer);
return answer;
}
}
Comments