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 41 | #include <iostream> using namespace std; int main() { int word[26]={0,}, count = 0; string input; cin >> input; for (int i = 0; i < input.length(); i++) { if (input[i] < 97) word[input[i] – 65]++; else word[input[i] – 97]++; } int max = 0, maxindex = 0; for (int i = 0; i < 26; i++) { if (max < word[i]) { max = word[i]; maxindex = i; } } for (int i = 0; i < 26; i++) { if (max == word[i]) count++; } if (count > 1) cout << “?”; else cout << (char)(maxindex + 65); } | cs |
참고) 알파벳의 아스키코드
A = 65, Z = 90
a = 97, z = 122