코딩 테스트/프로그래머스

[1차] 성격 유형 검사하기

필리힐리 2023. 2. 12. 19:15

class Solution {
    public String solution(String[] survey, int[] choices) {
        String answer = "";
        
        int survey_len = survey.length;
        
        int score_r = 0;
        int score_t = 0;
        int score_c = 0;
        int score_f = 0;
        int score_j = 0;
        int score_m = 0;
        int score_a = 0;
        int score_n = 0;
        
        for(int i = 0; i < survey_len; i++) {
            
            String chosen_char = "";
            int score = -4;
            
            // [RT, CF, MJ, AN]
            
            if(choices[i] < 4) {
                chosen_char = survey[i].substring(0, 1);
            } else if(choices[i] > 4) {
                chosen_char = survey[i].substring(1, 2);
            } else {
                
            }
            
            int real_score = score + choices[i];
            
            score = Math.abs(real_score);
            
            switch(chosen_char) {
                case "R" : 
                    score_r = score_r + score;
                    break;
                case "T" :
                    score_t = score_t + score;
                    break;
                case "C" : 
                    score_c = score_c + score;
                    break;
                case "F" :
                    score_f = score_f + score;
                    break;
                case "J" :
                    score_j = score_j + score;
                    break;
                case "M" : 
                    score_m = score_m + score;
                    break;
                case "A" : 
                    score_a = score_a + score;
                    break;
                case "N" : 
                    score_n = score_n + score;
                    break;
            }   
            
        } // for end
        
        String first_char = "";
        String second_char = "";
        String third_char = "";
        String fourth_char = "";
        
        if(score_r > score_t) {
            first_char = "R";
        } else if(score_t > score_r) {
            first_char = "T";
        } else {
            first_char = "R";
        }
        
        if(score_c > score_f) {
            second_char = "C";
        } else if(score_f > score_c) {
            second_char = "F";
        } else {
            second_char = "C";
        }
        
        if(score_j > score_m) {
            third_char = "J";
        } else if(score_m > score_j) {
            third_char = "M";
        } else {
            third_char = "J";
        }
        
        if(score_a > score_n) {
            fourth_char = "A";
        } else if(score_n > score_a) {
            fourth_char = "N";
        } else {
            fourth_char = "A";
        }
        
        answer = first_char + second_char + third_char + fourth_char;
        
        return answer;
    }
}