본문 바로가기

코딩테스트/프로그래머스

[프로그래머스] 추억 점수

728x90
반응형

문제

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

 

프로그래머스

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

programmers.co.kr

풀이와 코드

사진에 인물이 있을 경우에 인물의 그리움 점수를 더했다.

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<string> name, vector<int> yearning, vector<vector<string>> photo) {
    vector<int> answer;
    
    for(int i=0; i<photo.size(); i++){
        int score = 0;
        
        for(int j=0; j<name.size(); j++){
            if(find(photo[i].begin(), photo[i].end(), name[j]) != photo[i].end()){
                score += yearning[j];
            }
        }
        
        answer.push_back(score);
    }
    
    return answer;
}
728x90
반응형