C++:: 프로그래머스 <완주하지 못한 선수>

jahlee·2023년 3월 26일
0

프로그래머스_Lv.1

목록 보기
12/75
post-thumbnail

map 자료구조를 이용하면 상당히 쉽다. 이 문제에서 주의해야할점은 동명이인의 존재이다. set으로 구현하면 동명이인을 처리하지 못한다.

#include <string>
#include <vector>
#include <map>
using namespace std;

string solution(vector<string> participant, vector<string> completion)
{
    map <string, int> m;
    for(int i=0;i<participant.size();i++) m[participant[i]]++;// 인원수 등록
    for(auto c : completion)
        if (--m[c] == 0) m.erase(c);//해당 인물 map에서-- && value가 0 이 되면 삭제
    return m.begin()->first;
}

0개의 댓글