#include <stdio.h>
#include <string.h>
char GetSecondMostFrequentChar(char s[]) {
int count[256] = { 0 }; // 256 = ASCII table size
size_t size = strlen(s);
for (int i = 0; i < size; i++) {
count[s[i]]++;
}
int first = 0, second = 0;
for (int i = 0; i < 256; i++) {
if (count[i] > count[first]) {
second = first;
first = i;
}
else if (count[i] > count[second] && count[i] != count[first]) {
second = i;
}
}
return second;
}
int main() {
char str[] = "bbaddddccce";
printf("%c", GetSecondMostFrequentChar(str));
return 0;
}
/*
run:
c
*/