Returns string that occurs most often
#include<bits/stdc++.h>
#define ASCII_SIZE 256
using namespace std;
char mostOftenChar(char* strng)
{
int count[ASCII_SIZE] = {0};
int length = strlen(strng);
for (int i=0; i<length; i++)
count[strng[i]]++;
int max = -1;
char result;
for (int i = 0; i < length; i++) {
if (max < count[strng[i]]) {
max = count[strng[i]];
result = strng[i];
}
}
return result;
}
int main()
{
char strng[] = "most often character";
cout << "Most Often Character is "
<< mostOftenChar(strng);
}