https://school.programmers.co.kr/learn/courses/30/lessons/176963
unordered_map 자료구조를 사용하는 기본적인 문제이다.
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> solution(vector<string> name, vector<int> yearning, vector<vector<string>> photo) {
vector<int> answer;
unordered_map<string, int> map;
for (int i = 0; i < name.size(); i++)
map[name[i]] = yearning[i];
for (int i = 0; i < photo.size(); i++)
{
int sum = 0;
for (int j = 0; j < photo[i].size(); j++)
sum += map[photo[i][j]];
answer.push_back(sum);
}
return answer;
}
미니쉘 과제 끝나고 알고리즘을 너무 소홀히 했던 것 같다.... 다시 하루에 한 문제 이상 풀도록 해야겠다 파이팅~
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 대충 만든 자판 c++ (2) | 2023.05.22 |
---|---|
프로그래머스 공원 산책 c++ (0) | 2023.05.22 |
프로그래머스 덧칠하기 c++ (0) | 2023.05.22 |
달리기 경주 c++ (0) | 2023.04.28 |
프로그래머스 124 나라의 숫자(12899)(c++) (0) | 2023.04.12 |