Search
Duplicate
📗

배부를 마라토너

주차
문제번호
10546
언어
C++
티어
실버
유형
자료구조
해시를 사용한 집합과 맵
nj_Blog
nj_상태
이해도
100%
풀이
사람
이해도 2
13 more properties

문제접근

이름 중복이 가능하기 때문에 multiset으로 입력 받고, 들어온 마라토너들을 찾아서 하나씩 제거해주고 마지막에 남는 한 녀석 출력

놓쳤던 부분

multiset에서 erase를 하면 찾은 모든 노드를 삭제
find를 통해서 처음으로 찾은 노드의 iterator를 넘기면됨

코드

10740 KB

140 ms

#include <iostream> #include <set> #include <string> using namespace std; int main(void) { int n; string input; multiset<string> s; ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> input; s.insert(input); } for (int i = 0; i < n - 1; i++) { cin >> input; s.erase(s.find(input)); } cout << *s.begin(); return (0); }
C++
복사