https://school.programmers.co.kr/learn/courses/30/lessons/118666
각 성격유형과 값을 가지고 있어야 하므로 키-값 을 갖는 map 자료구조를 이용
import java.util.HashMap;
import java.util.Map;
class Solution {
public String solution(String[] survey, int[] choices) {
StringBuilder answer = new StringBuilder();
Map<Character,Integer> type = new HashMap<>();
type.put('R',0);
type.put('T',0);
type.put('C',0);
type.put('F',0);
type.put('J',0);
type.put('M',0);
type.put('A',0);
type.put('N',0);
for(int i=0;i<choices.length;i++){
if(choices[i]> 4) {
char t = survey[i].charAt(1);
type.put(t,type.get(t)+choices[i] - 4);
}
else if(choices[i] < 4) {
char t = survey[i].charAt(0);
type.put(t,type.get(t)+ (4-choices[i]));
}
}
answer.append(type.get('R')<type.get('T') ? 'T':'R');
answer.append(type.get('C')<type.get('F') ? 'F':'C');
answer.append(type.get('J')<type.get('M') ? 'M':'J');
answer.append(type.get('A')<type.get('N') ? 'N':'A');
return answer.toString();
}
}