_unordered_map을 사용해서 <string, int> bucket을 가지는 map생성
명수만큼 second에 지정
completion에 있으면 --하여 >0인 경우 answer로 지정
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
unordered_map<string, int> umap;
for(auto ele : participant){
umap[ele]++;
}
for(auto ele : completion){
umap[ele]--;
}
for(auto ele : umap){
if(ele.second)
return ele.first;
}
}
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
unordered_map<string, int> umap;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
for (auto player : participant) {
if (umap.end() == umap.find(player))
umap.insert(make_pair(player, 1));
else
umap[player]++;
}
for (auto player : completion)
umap[player]--;
for (auto player : participant) {
if (umap[player] > 0) {
answer = player;
break;
}
}
return answer;
}
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
unordered_map<string, int> umap;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
for (auto player : participant) {
if (umap.end() == umap.find(player))
umap.insert(make_pair(player, 1));
else
umap[player]++;
}
for (auto player : completion)
umap[player]--;
for (auto player : participant) {
if (umap[player] > 0) {
answer = player;
break;
}
}
return answer;
}
int main(void)
{
vector<string> part = { "mislav", "stanko", "mislav", "ana" };
vector<string> comp = { "stanko", "ana", "mislav" };
cout << solution(part, comp);
return 0;
}