https://programmers.co.kr/learn/courses/30/lessons/42576
코드
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
map<string, int> m;
for (auto& iter: participant)
if (m.find(iter) != m.end()) m[iter]++;
else m[iter] = 1;
for (auto& iter: completion) m[iter]--;
for (auto& iter: m) if(iter.second) answer = iter.first;
return answer;
}
|
cs |
풀이
간단한 map을 이용한 문제였습니다.
1. participant를 map에 저장해 줍니다.
2. completion를 map에서 빼 줍니다.
3. 남은 map의 값을 출력합니다.
'프로그래머스' 카테고리의 다른 글
[StrataScractch] Number Of Units Per Nationality [MySQL] (0) | 2022.06.25 |
---|---|
[프로그래머스] 124 나라의 숫자 [C/C++] (0) | 2022.06.23 |
프로그래머스 - 이중우선순위큐 [C/C++] (0) | 2022.06.20 |
프로그래머스 - 등굣길 [C/C++] (0) | 2022.06.20 |
프로그래머스 - 정수 삼각형 [C/C++] (0) | 2022.06.20 |