Programmers/Level 1
C++ / 프로그래머스 / 추억 점수
GitHubSeob
2023. 6. 24. 16:45
문제
https://school.programmers.co.kr/learn/courses/30/lessons/176963
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
map을 이용하면 간단한 문제이다.
name과 yearning을 매칭해서 map에 담아준다.
photo를 탐색하면서 map[이름]의 점수가 있다면 더해서 answer에 합산하여 저장한다.
코드
#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(photo.size(), 0);
int idx(0), idx2(0);
unordered_map<string, int>score;
for (idx = 0; idx < name.size(); ++idx) {
score[name[idx]] = yearning[idx];
}
for (idx = 0; idx < photo.size(); ++idx) {
for (idx2 = 0; idx2 < photo[idx].size(); ++idx2) {
answer[idx] += score[photo[idx][idx2]];
}
}
return answer;
}