[Programmers]_C++_Algorithm_추억점수

신치우·2025년 2월 25일

C++_algorithm

목록 보기
11/17

지난시간에 배운 undorderd_map 적용
특별할건 없는 문제
for문을 좀 for(auto x: y) 형식을 사용하는 것도 연습해보자

#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> score;
    
    for(int i = 0; i < name.size(); i++){
        score[name[i]] = yearning[i];
    }
    
    for(int i = 0; i< photo.size(); i++){
        int temp = 0;
        for(int j=0; j< photo[i].size();j++){
            if(score.find(photo[i][j]) != score.end()){
                temp += score[photo[i][j]];
            }
        }
        answer.push_back(temp);
    }
    
    return answer;
}
profile
https://shin8037.tistory.com/

0개의 댓글