DOTY

프로그래머스) Lv.1 - 성격 유형 검사하기 본문

Algorithm/ect

프로그래머스) Lv.1 - 성격 유형 검사하기

증식세포 2023. 3. 20. 16:09
728x90
반응형

코딩테스트 연습 - 성격 유형 검사하기 | 프로그래머스 스쿨 (programmers.co.kr)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


#include <bits/stdc++.h>

using namespace std;

string solution(vector<string> survey, vector<int> choices) {
    string answer = "";
    map<string, int> result;
    result.insert({"R", 0});
    result.insert({"T", 0});
    result.insert({"C", 0});
    result.insert({"F", 0});
    result.insert({"J", 0});
    result.insert({"M", 0});
    result.insert({"A", 0});
    result.insert({"N", 0});
    
    int survey_length = survey.size();
    
    for(int i = 0; i < survey_length; i++) {
        if(survey[i] == "RT") {
            if(choices[i] < 4) {
                result["R"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["T"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "TR") {
            if(choices[i] < 4) {
                result["T"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["R"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "CF") {
            if(choices[i] < 4) {
                result["C"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["F"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "FC") {
            if(choices[i] < 4) {
                result["F"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["C"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "JM") {
            if(choices[i] < 4) {
                result["J"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["M"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "MJ") {
            if(choices[i] < 4) {
                result["M"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["J"] += (choices[i] - 4);
            }
        }
        else if(survey[i] == "AN") {
            if(choices[i] < 4) {
                result["A"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["N"] += (choices[i] - 4);
            }
        }
        else {
            if(choices[i] < 4) {
                result["N"] += (4 - choices[i]);
            }
            else if(choices[i] > 4) {
                result["A"] += (choices[i] - 4);
            }
        }
    }
    
    if(result["R"] >= result["T"])
        answer += "R";
    else
        answer += "T";
    
    if(result["C"] >= result["F"])
        answer += "C";
    else
        answer += "F";
    
    if(result["J"] >= result["M"])
        answer += "J";
    else
        answer += "M";
    
    if(result["A"] >= result["N"])
        answer += "A";
    else
        answer += "N";
    
    return answer;
}

 

하기 귀찮은 날에는 쉬운거라도.... 히히...

728x90
반응형

'Algorithm > ect' 카테고리의 다른 글

4) 백준 1920 - 수 찾기  (0) 2023.05.25
백준) 1806 - 부분합  (0) 2023.04.26
프로그래머스) Lv.3 - 기지국 설치  (0) 2023.03.18
프로그래머스) Lv 1 - 최소직사각형  (0) 2023.03.07
프로그래머스) Lv.2 - 탑  (0) 2020.10.05
Comments