1. 문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
2. 소스코드
- 문제 자체는 단순 정렬 후 비교만으로도 해결가능하다.
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
sort(participant.begin(), participant.end());
sort(completion.begin(), completion.end());
for (int i = 0; i < completion.size(); i++) {
if (participant[i] != completion[i]) return participant[i];
}
return participant[participant.size()-1];
}
- 해쉬를 이용한 함수 풀이.
- unordered_map 이용.
#include <unordered_map>
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
unordered_map<string,int> map;
for (auto elem : completion){
if (map.find(elem) == map.end())
map[elem] = 1;
else
map[elem]++;
}
for (auto elem : participant)
{
if (map.end() == map.find(elem))
return elem;
else {
map[elem]--;
if (map[elem] < 0 ) return elem;
}
}
}
'알고리즘 > BOJ(백준)' 카테고리의 다른 글
[ 프로그래머스-lv2 / 완전탐색 ] 소수 찾기 (0) | 2020.04.09 |
---|---|
[ 프로그래머스-lv2 / 스택 ] 기능개발 (0) | 2020.04.09 |
[ 프로그래머스-Lv1 ] 실패율 (0) | 2020.04.03 |
[ 프로그래머스-Lv1 / 비트연산 ] [1차]비밀지도 (0) | 2020.04.03 |
[ 프로그래머스-Lv1 / 그리디 ] 체육복 (0) | 2020.04.02 |