코딩공부/프로그래머스
[프로그래머스]Lv1 성격 유형 검사하기 C++ (map)
usingsystem
2023. 9. 12. 17:09
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/118666?language=cpp
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
소스코드
map은 c#과 다르게 자동정렬됨 초기화안해도 바로 insert됨
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> survey, vector<int> choices) {
string answer = "";
map<char, int> m;
for (int i = 0; i < choices.size(); i++)
{
int choice = choices[i];
if (choice < 4)
{
m[survey[i][0]] += 4 - choice;
}
else
{
m[survey[i][1]] += choice - 4;
}
}
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;
}
728x90