Search
📗

베스트셀러

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

문제접근

놓쳤던 부분

for문안에서 erase를 하게 되면 seg fault가 남

코드

2024 KB

0 ms

#include <iostream> #include <set> int n; std::multiset<std::string> book; void input_setting() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); } void input() { std::string tmp; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> tmp; book.insert(tmp); } } void solution() { int max; std::string answer; max = 0; std::multiset<std::string>::iterator iter; for (iter = book.begin(); iter != book.end(); iter++) { if (max < static_cast<int>(book.count(*iter))) { answer = static_cast<std::string>(*iter); max = static_cast<int>(book.count(*iter)); } } std::cout << answer; } int main(void) { input_setting(); input(); solution(); return (0); }
C++
복사