728x90

전체 코드 - 수정 전
import java.util.*;
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
int[] score = {3,2,1,0,1,2,3};
// 성격 유형 등록하기
char[] mbti_char = {'R', 'T', 'C', 'F', 'J', 'M', 'A','N'};
HashMap<Character, Integer> mbti = new HashMap<>();
for(char c : mbti_char)
{
mbti.put(c, 0);
}
//["AN", "CF", "MJ", "RT", "NA"]
//[5, 3, 2, 7, 5]
char type ;
for(int i = 0 ; i< choices.length; i++)
{
if(choices[i] <= 3){
type = survey[i].charAt(0);
mbti.put(type, mbti.get(type)+score[choices[i]-1]);
}
else
{
type = survey[i].charAt(1);
mbti.put(type, mbti.get(type)+score[choices[i]-1]);
}
}
System.out.println(mbti);
for(int i = 0; i<4; i++)
{
if(mbti.get(mbti_char[2*i]) >= mbti.get(mbti_char[2*i+1]))
answer += mbti_char[2*i];
else
answer += mbti_char[2*i+1];
}
return answer;
}
}

728x90
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv.2 구명 보트 (자바) (0) | 2024.06.29 |
---|---|
[프로그래머스] Lv.2 올바른 괄호 (자바) (0) | 2024.06.26 |
[프로그래머스] Lv.1 체육복 (java) (0) | 2024.05.09 |
[프로그래머스] Lv.1 공원산책 (java) (0) | 2024.05.07 |
[프로그래머스] Lv.1 달리기 경주 (Java) (0) | 2024.05.05 |