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

1 개요[ | ]

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

2 C++[ | ]

#include <string>
#include <vector>
#include <map>
using namespace std;

string solution(vector<string> survey, vector<int> choices) {
    map<char,int> m;
    for(int i=0; i<choices.size(); i++) {
        int choice = choices[i];
        if(choice == 4) continue;
        if(choice < 4) {
            m[survey[i][0]] += 4-choice;
        } else {
            m[survey[i][1]] += choice-4;
        }
    }
    string answer = "";
    answer += m['R']>=m['T'] ? 'R' : 'T';
    answer += m['C']>=m['F'] ? 'C' : 'F';
    answer += m['J']>=m['M'] ? 'J' : 'M';
    answer += m['A']>=m['N'] ? 'A' : 'N';
    return answer;
}
#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) {
    map<char,int> m;
    for(int i=0; i<choices.size(); i++) {
        int choice = choices[i];
        if(choice == 4) continue;
        if(choice < 4) {
            m[survey[i][0]] += 4-choice;
        } else {
            m[survey[i][1]] += choice-4;
        }
    }
    string answer = "";
    for(int i = 0; i < 4; ++i){
        if(m[MBTI[i][0]] >= m[MBTI[i][1]]) {
            answer += MBTI[i][0];
        } else {
            answer += MBTI[i][1];
        }
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}