Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 백준 17070번 c++
- 코테
- Unity
- 2870번
- 백준
- 2870번 수학숙제 c++
- 유니티
- 백준 c++ 2870번
- 수학숙제
- 2468 c++
- c++
- 오브젝트 풀링
- Algorithm
- 2870번 c++
- C#
- 코딩테스트
- 프로그래머스
- Lv.3
- 백준 c++ 2468번
- 백준 17070번
- 2870번 수학숙제
- 17070번
- Lv2
- 백준 1103번 c++
- 플레이어 이동
- Beakjoon
- 백준 1103번
- 백준 1103번 게임
- 백준 2870번
- dfs
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C++] Lv.1 완주하지 못한 선수 본문
https://school.programmers.co.kr/learn/courses/30/lessons/42576
1. 정답코드 및 핵심 아이디어, 유의사항
- completion의 길이는 participant의 길이보다 1 작음
- 동명이인이 있을 수 있음
주석 참조
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> participant, vector<string> completion)
{
string answer;
map<string, int> mapset;
for (auto elem : completion)
{
if (mapset.end() == mapset.find(elem))
mapset.insert({ elem, 1 });
else
mapset[elem]++;
}
for (auto elem : participant)
{
if (mapset.end() == mapset.find(elem))
return elem;
else
{
mapset[elem]--;
if (mapset[elem] < 0)
return elem;
}
}
return NULL;
}
+ 다른 풀이
#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());
for (int i = 0; i < completion.size(); i++)
if (participant[i] != completion[i])
return participant[i];
return participant[participant.size() - 1];
}
'CodingTest > Programmers Lv.1' 카테고리의 다른 글
[프로그래머스 C#] Lv.1 동영상 재생기 (PCCP 기출문제 1번) (0) | 2024.09.22 |
---|---|
[프로그래머스 C#] Lv.1 신고 결과 받기 (0) | 2024.02.14 |
[프로그래머스 C#] Lv.1 개인정보 수집 유효기간 (0) | 2024.02.13 |
[프로그래머스 C#] Lv.1 옹알이(2) (0) | 2024.01.15 |
[프로그래머스 C#] Lv.1 가장 많이 받은 선물 (0) | 2024.01.04 |