입력받은 글에서 조건에 맞는(가장 많이 등장한, 동일하다면 알파벳순으로) 알파벳을 출력하면 된다.
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 |
'BOJ' 카테고리의 다른 글
15271 친구 팰린드롬 2 (0) | 2018.02.17 |
---|---|
15312 이름 궁합 (0) | 2018.02.17 |
14950 정복자 (0) | 2018.02.17 |
14949 외계 미생물 (0) | 2018.02.17 |
2855 흥미로운 수열 (0) | 2017.12.14 |