●문제

●입출력

사용 알고리즘 : Hash / unordered_map
문제해독 : 참여자가 완주자보다 항상 +1
완주자 는 참여자 -1 임
참여자를 map의 ++
완주자를 map의 --를 해줬을때
완주자가 0보다 클때 즉 남은사람을 구하는 문제
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
string solution(vector<string> participant, vector<string> completion)
{
//참여자선수이름, 해당 이름의 갯수
unordered_map<string, int>playerMap;
for (int i = 0; i < participant.size(); i++)
playerMap[participant[i]]++;
for (int i = 0; i < completion.size(); i++)
playerMap[completion[i]]--;
for (auto it : playerMap)
{
//완주하지못한 참가자
if (it.second > 0)
{
return it.first;
}
}
return "";
}
Lv: 1
점수 : 1
'C++ 프로그래머스 > Hash' 카테고리의 다른 글
| 프로그래머스(C++) - 의상 (1) | 2025.08.11 |
|---|---|
| 프로그래머스(C++) - 전화번호 목록 (0) | 2025.08.08 |
| Algorithm - Hash (0) | 2025.08.08 |
