구현문제입니다.
survey와 choice에 따라 어떤 사람이 점수를 얻는지를 판별하면 되는 문제입니다.
설문에 참여하는 사람은 8명으로 정해져 있습니다.
[구현 코드]
public class Solution {
    private static class Solution{
        // 순서대로 R ,T, F, C, M, J, A, N
        private static int[] count = new int[8];
        private static char[] arr = {'R', 'T', 'F','C', 'M', 'J', 'A', 'N'};
        private static int point(int value){
            if(value==1 || value==7){
                return 3;
            }else if(value==2 || value==6){
                return 2;
            }else{
                return 1;
            }
        }
        private static String solution(String[] survey, int[] choices){
            StringBuilder sb = new StringBuilder();
            for(int i=0; i< survey.length; i++){
                if(choices[i]==4) continue;
                String current = survey[i];
                int value = choices[i];
                if(current.equals("RT")){
                    if(value<4){
                        count[0] += point(value);
                    }else{
                        count[1] += point(value);
                    }
                }else if(current.equals("TR")){
                    if(value<4){
                        count[1] += point(value);
                    }else{
                        count[0] += point(value);
                    }
                }else if(current.equals("FC")){
                    if(value<4){
                        count[2] += point(value);
                    }else{
                        count[3] += point(value);
                    }
                }else if(current.equals("CF")){
                    if(value<4){
                        count[3] += point(value);
                    }else{
                        count[2] += point(value);
                    }
                }else if(current.equals("MJ")){
                    if(value<4){
                        count[4] += point(value);
                    }else{
                        count[5] += point(value);
                    }
                }else if(current.equals("JM")){
                    if(value<4){
                        count[5] += point(value);
                    }else{
                        count[4] += point(value);
                    }
                }else if(current.equals("AN")){
                    if(value<4){
                        count[6] += point(value);
                    }else{
                        count[7] += point(value);
                    }
                }else if(current.equals("NA")){
                    if(value<4){
                        count[7] += point(value);
                    }else{
                        count[6] += point(value);
                    }
                }
            }
            for(int i=0; i< count.length; i+=2){
                if(count[i]> count[i+1]){
                    sb.append(arr[i]);
                }else if(count[i]< count[i+1]){
                    sb.append(arr[i+1]);
                }else{
                    // 같을 때
                    int a = arr[i]-'A';
                    int b = arr[i+1]-'A';
                    if(a>b){
                        sb.append(arr[i+1]);
                    }else{
                        sb.append(arr[i]);
                    }
                }
            }
            return sb.toString();
        }
    }
}'알고리즘' 카테고리의 다른 글
| 백준 - 11779 최소비용 구하기 2(Java) (0) | 2022.09.13 | 
|---|---|
| 백준 - 11909 배열 탈출(Java) (0) | 2022.09.13 | 
| 백준 - 17070 파이프 옮기기1(Java) (0) | 2022.09.11 | 
| 프로그래머스 - 두 큐 합 같게 만들기(Java) (0) | 2022.09.03 | 
| 프로그래머스 - 등산 코스 정하기(Java) (3) | 2022.09.03 | 
 
                  
                 
                  
                 
                  
                