- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/118666
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/118666. 성격 유형 검사하기
풀이 시간 : 58분
import java.util.*;
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
HashMap<Character, Integer> map = new HashMap<>();
map.put('R', 0);
map.put('T', 0);
map.put('C', 0);
map.put('F', 0);
map.put('J', 0);
map.put('M', 0);
map.put('A', 0);
map.put('N', 0);
for (int i = 0; i < survey.length; i++) {
if (choices[i] < 4) {
map.put(survey[i].charAt(0), map.get(survey[i].charAt(0)) + 4 - choices[i]);
} else if (choices[i] > 4) {
map.put(survey[i].charAt(1), map.get(survey[i].charAt(1)) + choices[i] - 4);
}
}
char[] typeOne = {'R', 'C', 'J', 'A'};
char[] typeTwo = {'T', 'F', 'M', 'N'};
for (int i = 0; i < typeOne.length; i++) {
if (map.get(typeOne[i]) >= map.get(typeTwo[i])) {
answer += typeOne[i];
} else {
answer += typeTwo[i];
}
}
return answer;
}
}