-
프로그래머스 완주하지못한선수 [C++] feat.다양한 풀이방법소프트웨어전공/알고리즘 문제풀이 2021. 10. 6. 21:20
https://programmers.co.kr/learn/courses/30/lessons/42576
[문제 접근]
- 두 개의 벡터 스트링 배열이 주어지고, 이 둘을 비교한다.
- 참가자 중에 동명이인이 있다는 조건이 있지만, 완주하지 못한 선수는 단 한명이기 때문에 어려운 요구사항은 아니었다.
- 반복문을 돌며 두 배열을 비교하고 같은것만 참가자 배열에서 삭제해주면 결국 단 하나의 요소만 남을 것이다.
[C++ _ 중첩 반복문]
[새로 알게된 것]
- <algorithm>에 속해있는 find(), erase()
- auto it 구문
그러나 해당 풀이는 시간복잡도가 N^2라서 효율성 테스트를 통과하지 못했다.
[정렬 후 비교]
해당 풀이는 출제의도와는 조금 벗어난 기법을 사용했지만, 코드가 훨씬 깔끔하다.
[Hash Table]
unordered_map
[참고 자료 출처]
https://boycoding.tistory.com/226
'소프트웨어전공 > 알고리즘 문제풀이' 카테고리의 다른 글
백준 1008번 : A/B [C++] (0) 2021.09.28 프로그래머스 폰켓몬 _ [C++] (0) 2021.09.28 C++ 숫자의 총 개수 (0) 2021.09.26 백준 1152번 단어의 개수 _ [C++] (0) 2021.09.25 백준 1110번 더하기 사이클 [C++] (0) 2021.09.24