Created
April 27, 2020 08:06
-
-
Save DongguemYoo/2bd6e3686ce22ae44cdb75fa27b1007d to your computer and use it in GitHub Desktop.
코딩테스트 연습 완주하지 못한 선수
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <map> | |
using namespace std; | |
string solution(vector<string> participant, vector<string> completion) { | |
string answer = ""; | |
map<string, int> mm;//dictionary라고 보면됨 | |
int size = participant.size(); | |
for(int i=0; i<size; i++) { | |
mm[participant[i]]++; | |
} | |
size = completion.size(); | |
for(int i=0; i<size; i++) { | |
mm[completion[i]]++; | |
} | |
// 모든 원소를 삽입 한다. | |
// 중복 허용함 second 값만 늘어난다. | |
// 만약 second 값이 홀수이면 짝이 없으므로 탈락자이다 | |
map<string, int>::iterator it; | |
for(it = mm.begin(); it != mm.end(); it++) { | |
int n = it->second; | |
if (n % 2 == 1) { | |
//n이 홀수이면 짝이 없어서 탈락한 사람이 된다 | |
answer =it->first; | |
break; | |
} | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment