알고리즘 문제 풀이/백준 온라인 저지
백준 1157번: 단어 공부 (C++)
Hugxy
2019. 9. 25. 21:41
https://www.acmicpc.net/problem/1157
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #pragma warning(disable :4996) #include<iostream> #include<string> using namespace std; int alp[26]; int main(void) { ios::sync_with_stdio(false); cin.tie(0); string str; cin >> str; for (int i = 0; i < str.length(); i++) { if (str[i] >= 'a' && str[i] <= 'z') alp[str[i] - 'a']++; else alp[str[i] - 'A']++; } int Max = 0, idx =0; for (int i = 0; i < 26; i++) { if (Max < alp[i]) { idx = i; Max = alp[i]; } } for (int i = 0; i < 26; i++) { if (alp[i] == Max && i != idx) { cout << "?"; return 0; } } char ans = idx + 'A'; cout << ans; return 0; } | cs |