"프로그래머스 118666 성격 유형 검사하기"의 두 판 사이의 차이

(새 문서: ==개요== {{프로그래머스|레벨=1|페이지=2|분류=2022 KAKAO TECH INTERNSHIP}} ==C++== <syntaxhighlight lang='cpp'> #include <string> #include <vector> #include <map> using...)
 
 
25번째 줄: 25번째 줄:
     answer += m['J']>=m['M'] ? 'J' : 'M';
     answer += m['J']>=m['M'] ? 'J' : 'M';
     answer += m['A']>=m['N'] ? 'A' : 'N';
     answer += m['A']>=m['N'] ? 'A' : 'N';
    return answer;
}
</syntaxhighlight>
<syntaxhighlight lang='cpp'>
#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;
     return answer;
}
}
</syntaxhighlight>
</syntaxhighlight>

2023년 12월 14일 (목) 01:02 기준 최신판

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 }}