728x90
반응형
SMALL
[프로그래머스] Lev 2. 성격 유형 검사하기
https://school.programmers.co.kr/learn/courses/30/lessons/118666



걸린시간: 33분
import java.util.*;
import java.io.IOException;
class Solution {
static Map<Integer, String[]> score = new LinkedHashMap<>();
static Map<String, Integer> counting = new HashMap<>();
public static void setUp(){
score.put(0,new String[]{"R","T"});
score.put(1,new String[]{"C","F"});
score.put(2,new String[]{"J","M"});
score.put(3,new String[]{"A","N"});
counting.put("R", 0);
counting.put("T", 0);
counting.put("C", 0);
counting.put("F", 0);
counting.put("J", 0);
counting.put("M", 0);
counting.put("A", 0);
counting.put("N", 0);
}
public static int score(int num, boolean isAgree){
if (isAgree){
return switch (num) {
case 1, 7 -> 3;
case 2, 6 -> 2;
case 3, 5 -> 1;
default -> 0;
};
} else {
return switch (num) {
case 1, 7 -> -3;
case 2, 6 -> -2;
case 3, 5 -> -1;
default -> 0;
};
}
}
public static String solution(String[] survey, int[] choices) {
setUp();
StringBuilder sb = new StringBuilder();
for (int i=0; i<survey.length; i++){
String[] cur = survey[i].split("");
String x1 = cur[0];
String x2 = cur[1];
boolean isAgree = false;
if (choices[i]<4){
isAgree=true;
} else if (choices[i]>4){
isAgree=false;
}
counting.put(x1, counting.get(x1)+score(choices[i], isAgree));
counting.put(x2, counting.get(x2)+score(choices[i], !isAgree));
}
for (int i=0; i<score.size(); i++){
String[] cur = score.get(i);
String x1 = cur[0];
String x2 = cur[1];
System.out.println(x1 +" : " +counting.get(x1));
System.out.println(x2 +" : " +counting.get(x2));
String alpabet = counting.get(x1)>=counting.get(x2)?x1:x2;
sb.append(alpabet);
}
return sb.toString();
}
}728x90
반응형
LIST
'Personal Studying~ > 자바문제 풀어보기' 카테고리의 다른 글
| [프로그래머스] Lev 2. 신고 결과 받기 (0) | 2025.09.24 |
|---|---|
| [프로그래머스] Lev 2. 행렬 테두리 회전하기 (0) | 2025.09.23 |
| [재귀, 백트래킹] 연산자 끼워넣기(BOJ 14888) (1) | 2025.05.15 |
| [프로그래머스]lev2 순위검색 (0) | 2023.09.20 |
| [백준] 1427번: 소트인사이드 (0) | 2021.11.05 |