https://programmers.co.kr/learn/challenges
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <string> #include <vector> #include <algorithm> #include <sstream> #include <iostream> using namespace std; string solution(vector<string> table, vector<string> languages, vector<int> preference) { string answer = ""; vector<string> domain_list = { "CONTENTS", "HARDWARE", "PORTAL", "SI", "GAME"}; vector<string> lang_list = {"JAVA", "JAVASCRIPT", "SQL", "PYTHON", "C++", "KOTLIN", "PHP", "C#", "C"}; int tb[9][5] = {0}; int col = 0; int row = 0; for(int i =0 ;i < table.size(); i++){ string stringBuffer; istringstream ss(table[i]); vector<string> s; while(getline(ss, stringBuffer, ' ')){s.push_back(stringBuffer);} row = find(domain_list.begin(), domain_list.end(), s[0]) - domain_list.begin(); for(int i = 1; i < s.size() ; i++){ col = find(lang_list.begin(), lang_list.end(), s[i]) - lang_list.begin(); tb[col][row] = 6 - i; } } int sum = 0;int max = 0;int idx = 0; for(int i = 0; i < domain_list.size();i++){ sum = 0; for(int j = 0; j < languages.size(); j++){ int pre1 = find(lang_list.begin(), lang_list.end(), languages[j]) - lang_list.begin(); sum += (tb[pre1][i] * preference[j]); } if(max < sum){ max = sum; idx = i; } } answer = domain_list[idx]; return answer; } | cs |
728x90
'개발 > 알고리즘' 카테고리의 다른 글
프로그래머스_평행 (0) | 2024.04.19 |
---|---|
프로그래머스_구명보틀 (0) | 2021.08.26 |
[알고리즘]나머지성질을 이용한 문제 (0) | 2021.08.12 |
1780_종이의 갯수 (0) | 2020.12.20 |
1645_랜선 자르기 (0) | 2020.12.08 |