알고리즘 문제 풀이
프로그래머스 - 직업군 추천하기
가나무마
2021. 8. 28. 01:10
본 알고리즘 풀이는 Routine Study에서 진행하고 있습니다.
저를 포함한 구성원이 대부분 초보이므로, 원하시는분은 언제라도 들어오셔도 좋습니다.
문의는 댓글 바람.
GitHub - ROUTINE-STUDY/Algorithm: 초보 알고리즘 스터디 / 누구나 참여 가능
초보 알고리즘 스터디 / 누구나 참여 가능 :runner:. Contribute to ROUTINE-STUDY/Algorithm development by creating an account on GitHub.
github.com
코딩테스트 연습 - 4주차
개발자가 사용하는 언어와 언어 선호도를 입력하면 그에 맞는 직업군을 추천해주는 알고리즘을 개발하려고 합니다. 아래 표는 5개 직업군 별로 많이 사용하는 5개 언어에 직업군 언어 점수를 부
programmers.co.kr

[문제 설명]
그냥 구현해주면 되는 문제같습니다. 딱히 뭔가를 해줘야 하는 문제 같지는 않습니다.
배열을 써도 되겠지만, Map을 써서 풀어봤습니다.
[처음 생각한 접근 방법]
import java.util.*;
class Solution {
public String solution(String[] table, String[] languages, int[] preference) {
String answer = "";
Map<String,Map<String, Integer>> database = new HashMap<>();
for (String company : table) {
int score = 5;
String[] sArray = company.split(" ");
Map<String, Integer> tempMap = new HashMap();
for (int i = 1; i < sArray.length; i++) {
tempMap.put(sArray[i], score--);
}
database.put(sArray[0],tempMap);
}
Map<String, Integer> jobScoreMap = new HashMap<>();
for (String key : database.keySet()) {
Map<String,Integer> tempMap = database.get(key);
int totalScore = 0;
for (int i = 0; i < languages.length; i++) {
totalScore += tempMap.getOrDefault(languages[i],0) * (preference[i]);
}
jobScoreMap.put(key, totalScore);
}
int max = 0;
for (int score : jobScoreMap.values()) {
if (score > max) {
max = score;
}
}
List<String> highPointJob = new ArrayList<>();
for (String job : jobScoreMap.keySet()) {
if (jobScoreMap.get(job) == max) highPointJob.add(job);
}
Collections.sort(highPointJob);
return highPointJob.get(0);
}
}