-
[1302] 베스트셀러BOJ 2022. 4. 1. 16:32
https://www.acmicpc.net/problem/1302
1302번: 베스트셀러
첫째 줄에 오늘 하루 동안 팔린 책의 개수 N이 주어진다. 이 값은 1,000보다 작거나 같은 자연수이다. 둘째부터 N개의 줄에 책의 제목이 입력으로 들어온다. 책의 제목의 길이는 50보다 작거나 같고
www.acmicpc.net
multiset에 전부 넣고, 순회하면서 count()가 크거나, count()가 동일하며 사전순으로 앞서있을때 갱신한다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;int n, cnt;multiset<string> st;string ans;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;while (n--) {string s;cin >> s;st.insert(s);}for (auto& i : st) {if (ans.empty() || cnt < st.count(i) ||(cnt == st.count(i) && ans > i)) {ans = i;cnt = st.count(i);}}cout << ans;return 0;}
'BOJ' 카테고리의 다른 글
[9375] 패션왕 신해빈 (0) 2022.04.07 [18111] 마인크래프트 (0) 2022.04.03 [1940] 주몽 (0) 2022.03.30 [3649] 로봇 프로젝트 (0) 2022.03.30 [2458] 키 순서 (0) 2022.03.29