https://programmers.co.kr/learn/courses/30/lessons/84325
[난이도] level1
[유형] 구현
[풀이]
단순 구현 문제입니다.
#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
map<string,map<string,int>> mp;
void split(string str){
vector<string> ret;
int idx;
str+=' ';
while((idx=str.find(' '))!=string::npos){
ret.push_back(str.substr(0,idx));
str=str.substr(idx+1);
}
map<string,int> m;
for(int i=1;i<=5;i++){
m[ret[i]]=6-i;
}
mp[ret[0]]=m;
}
string solution(vector<string> table, vector<string> languages, vector<int> preference) {
string answer = "";
for(auto t : table) split(t);
int mv=0;
for(auto p : mp){
auto job = p.first;
auto tb = p.second;
int v=0;
for(int i=0;i<languages.size();i++) v+=preference[i]*tb[languages[i]];
if(v>mv){
answer = job;
mv=v;
}
}
return answer;
}
https://github.com/has2/Problem-Solving/blob/master/programmers/level1/직업군_추천하기.cpp
'Problem-Solving > Programmers' 카테고리의 다른 글
[프로그래머스][level4] 블록게임 (C++) (0) | 2021.08.26 |
---|---|
[프로그래머스][level4] 징검다리 (C++) (0) | 2021.08.26 |
[프로그래머스][level3] 브라이언의 고민 (C++) (0) | 2021.08.23 |
[프로그래머스][level3] 광고 삽입 (C++) (0) | 2021.08.22 |
[프로그래머스][level3] 110 옮기기 (C++) (0) | 2021.08.22 |