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

jihunnit·2022년 9월 15일
0

코테

목록 보기
16/20

성격 유형 검사하기

이거는 그니까.. 문자열의 탈을 쓴 문제이지
실제로 문자열로 다룰 건 없다.

뭐라고 설명해야 하는거지..그냥 key로 Value를 찾는
자료구조들 (C++, Java의 map, python의 dictionary 등등)
사용법을 잘 알고 있다면
어려움 없이 풀 수 있지 않을까??

간단한 문제로 하루를 날로 먹는 느낌이 들기도 하지만
하루종일 문제 푸느라 에너지 쏟는 날도 있고
이렇게 간단한 문제를 기분좋게 푸는 날도 있고 ㅎㅎ

코드는 다음과 같다

#include <string>
#include <vector>
#include <map>
using namespace std;
map<char,int> m;
string solution(vector<string> survey, vector<int> choices) {
    string answer = "";
    m['R']=0;
    m['T']=0;
    m['C']=0;
    m['F']=0;
    m['J']=0;
    m['M']=0;
    m['A']=0;
    m['N']=0;
    for(int i=0;i<survey.size();i++){
        if(choices[i]<4){
            m[survey[i][0]]+=(4-choices[i]);
        }else if(choices[i]>4){
            m[survey[i][1]]+=(choices[i]-4);
        }else continue;
    }
    if(m['R']>=m['T']){
        answer.push_back('R');
    }else{
        answer.push_back('T');
    }
    if(m['C']>=m['F']){
        answer.push_back('C');
    }else{
        answer.push_back('F');
    }
    if(m['J']>=m['M']){
        answer.push_back('J');
    }else{
        answer.push_back('M');
    }
    if(m['A']>=m['N']){
        answer.push_back('A');
    }else{
        answer.push_back('N');
    }
    return answer;
}
profile
인간은 노력하는 한 방황한다

0개의 댓글