알고리즘/프로그래머스

Programers 추억 점수/ C++

내이름은 킹햄찌 2023. 4. 1. 16:31

https://school.programmers.co.kr/learn/courses/30/lessons/176963

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

아이디어

해쉬맵을 이용하여  추억점수가 부여되어 있는 사람들의 이름을 저장해두고 사진마다 점수가 부여되어야 하는 사람이 있는지를 확인하면 됨

 

#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> yearningMap;
    for(int i=0;i<name.size();i++)
        yearningMap[name[i]] = yearning[i];
    
    for(auto poto : photo){
        int yearningPoint =0;
        for(auto person : poto){
            yearningPoint+=yearningMap[person];
        }
        answer.push_back(yearningPoint);
    }
    return answer;
}