자윤이와고리즘/Code
[프로그래머스] 완주하지 못한 선수
EUJU
2019. 10. 8. 14:08
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
string name = "";
int num = 0;
int flag = 0;
sort(participant.begin(), participant.end());
sort(completion.begin(), completion.end());
for(int i = 0;i < completion.size(); i++){
name = participant[i];
if(participant[i] != completion[i]){
answer = participant[i];
flag = 1;
break;
}
}
if (flag ==0)
answer = participant[participant.size()-1];
return answer;
}
이거 전에 풀 때는 진짜 큐?인가 그런거 써서 풀려다가 포기했었다. 너무 어렵게 생각하지 말자!