Level 2. 추억 점수
그냥 이중 for문을 쓸 걸 그랬다.
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <numeric>
using namespace std;
vector<int> solution(vector<string> name, vector<int> yearning, vector<vector<string>> photo)
{
vector<int> answer(photo.size());
size_t size = name.size();
unordered_map<string, int> umap;
for (int i = 0; i < size; ++i)
umap[name[i]] = yearning[i];
auto func = [&umap](int sum, string& s){ return sum + umap[s]; };
auto func2 = [&func](vector<string>& v) { return accumulate(v.begin(), v.end(), 0, func); };
transform(photo.begin(), photo.end(), answer.begin(), func2);
return answer;
}
'자료구조 & 알고리즘 > 프로그래머스' 카테고리의 다른 글
Level 2. 타겟 넘버 (0) | 2023.04.07 |
---|---|
Level 2. 스킬트리 (0) | 2023.04.06 |
Level 2. 최솟값 만들기 (0) | 2023.04.04 |
Level 2. 큰 수 만들기 (0) | 2023.04.03 |
Level 2. 다음 큰 숫자 (0) | 2023.04.02 |