#include <iostream>
char GetSecondMostFrequentChar(std::string s) {
int count[256] = {0}; // 256 = ASCII table size
for (int i = 0; i < s.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 char(second);
}
int main() {
std::string str = "bbaddddccce";
std::cout << GetSecondMostFrequentChar(str);
return 0;
}
/*
run:
c
*/