BOJ
1371 가장 많은 글자
공부정리
2018. 2. 17. 12:16
입력받은 글에서 조건에 맞는(가장 많이 등장한, 동일하다면 알파벳순으로) 알파벳을 출력하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> #include <algorithm> using namespace std; int a; pair<int, int> cnt[26]; char c, b; int main() { while (scanf("%c", &c) != EOF) if (c >= 'a' && c <= 'z') cnt[c - 'a'].first--; for (int i = 0; i < 26; i++) cnt[i].second = i; stable_sort(cnt, cnt + 26); printf("%c", char(cnt[0].second + 'a')); for (int i = 1; i < 26; i++) { if (cnt[i].first != cnt[i - 1].first) break; printf("%c", char(cnt[i].second + 'a')); } return 0; } | cs |