[프로그래머스] 성격 유형 검사하기

less than 1 minute read

문제 설명

https://school.programmers.co.kr/learn/courses/30/lessons/118666

제한사항

  • 생략

풀이

15분
레벨1 문제로 어려운 부분은 없었다. 다만, 현 시간 기준(2022-08-18-19:11) 해당 문제를 C++ 언어로 풀이한 사람이 나 뿐이다…!!
아싸 1등

코드

// 06:50 ~ 07:05
#include <string>
#include <vector>
#include <map>

using namespace std;

char MBTI[4][2] = {
    {'R','T'},
    {'C','F'},
    {'J','M'},
    {'A','N'}
};

string solution(vector<string> survey, vector<int> choices) {
    string ans = "";
    map<char,int> score;
    
    for(int i = 0; i < survey.size(); ++i){
        if(choices[i] < 4){
            score[survey[i][0]] += (4 - choices[i]);
        } else{
            score[survey[i][1]] += (choices[i] - 4); 
        }
    }
    
    for(int i = 0; i < 4; ++i){
        if(score[MBTI[i][0]] >= score[MBTI[i][1]]) ans += MBTI[i][0];
        else ans += MBTI[i][1];
    }
    
    return ans;
}