"프로그래머스 42576 완주하지 못한 선수"의 두 판 사이의 차이

(새 문서: ==개요== {{프로그래머스|레벨=1|페이지=4|분류=해}} ==C++== <syntaxhighlight lang='cpp'> #include <string> #include <vector> #include <algorithm> using namespace std;...)
 
 
1번째 줄: 1번째 줄:
==개요==
==개요==
{{프로그래머스|레벨=1|페이지=4|분류=}}
{{프로그래머스|레벨=1|페이지=4|분류=해시}}


==C++==
==C++==

2023년 12월 26일 (화) 01:16 기준 최신판

1 개요[ | ]

프로그래머스 42576 완주하지 못한 선수

2 C++[ | ]

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

string solution(vector<string> participant, vector<string> completion) {
    sort(participant.begin(), participant.end());
    sort(completion.begin(), completion.end());
    vector<string> v(1);
    set_difference(participant.begin(), participant.end(), completion.begin(), completion.end(), v.begin());
    return v[0];
}
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

string solution(vector<string> participant, vector<string> completion) {
    sort(participant.begin(), participant.end());
    sort(completion.begin(), completion.end());
    int n = completion.size();
    for(int i=0; i<n; i++) {
        if(participant[i] != completion[i]) {
            return participant[i];
        }
    }
    return participant[n];
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}