-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrToTokens.cpp
More file actions
58 lines (54 loc) · 1.08 KB
/
Copy pathstrToTokens.cpp
File metadata and controls
58 lines (54 loc) · 1.08 KB
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
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
using namespace std;
char getMostFreqLetter(string s)
{
const int NUM_ASCII = 128;
int ascii_array[NUM_ASCII] = { };
int max = 0;
int maxIndex = 0;
for(int i = 0; i < s.length(); ++i)
{
if (s[i] == ' ')
continue;
ascii_array[(int)s[i]]++;
}
for(int i = 0; i < NUM_ASCII; i++)
{
if(ascii_array[i] > max)
{
max = ascii_array[i];
maxIndex = i;
}
}
return (char)maxIndex;
}
void StrToTokens(string s)
{
char newChar;
string temp = "";
for(int i=0; i < s.length(); i++)
{
if(s[i] != ' ')
{
temp += s[i];
if (i == s.length() - 1) {
cout << " '" << temp << "'\n";
}
}
else {
cout << " '" << temp << "',";
temp = "";
}
}
}
int main()
{
string s = "Life is not a problem to be solved but a reality to be experienced.";
cout << "The string to convert to separate tokens: '" << s << "'" << endl;
cout << endl;
StrToTokens(s);
char maxCharacter = getMostFreqLetter(s);
cout << endl;
cout << "Most Frequent Letter: " << maxCharacter << endl;
}