-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_word.cpp
More file actions
52 lines (39 loc) · 949 Bytes
/
count_word.cpp
File metadata and controls
52 lines (39 loc) · 949 Bytes
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
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <vector>
using namespace std;
int alphabet[26];
int main(void){
int i;
string input;
vector<int> input_array;
cin >> input;
copy(input.begin(), input.end(), back_inserter(input_array));
for(i = 0; i < input_array.size(); i++){
int index;
if(input_array[i] > 90){
index = input_array[i]-97;
alphabet[index] += 1;
} else {
index = input_array[i]-65;
alphabet[index] += 1;
}
}
int max = 0;
int max_index;
int max_count = 0;
for(i = 0; i < 26; i++){
if(alphabet[i] > max){
max = alphabet[i];
max_index = i;
max_count = 1;
} else if(alphabet[i] == max){
max_count++;
}
}
if(max_count >= 2){
cout << "?" << endl;
} else {
cout << (char)(max_index + 65) << endl;
}
return 0;
}