풀이과정
참가자 중에 동명이인이 있을 수 있으므로, map에 participant key의 value값을 더해주고
completion일 경우 key의 value값을 빼준다.
마지막으로 map을 다 돌며 value값이 1인 경우일 때 출력해준다.
참가를 했지만, 완주를 못 했을 경우이기 때문이다.
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
map<string, int> m;
for(int i = 0; i < participant.size(); i++){
m[participant[i]]++;
}
for(int i = 0; i < completion.size(); i++){
m[completion[i]]--;
}
for(auto i : m){
if(i.second == 1) answer = i.first;
}
return answer;
}
'🍞 Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스][Level1] 2016년 c++ (0) | 2022.09.03 |
---|---|
[프로그래머스][Level1] 음양 더하기 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 예산 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 없는 숫자 더하기 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 숫자 문자열과 영단어 c++ (0) | 2022.09.03 |