Skip to content

Instantly share code, notes, and snippets.

@mejibyte
Created September 10, 2011 17:51
Show Gist options
  • Select an option

  • Save mejibyte/1208572 to your computer and use it in GitHub Desktop.

Select an option

Save mejibyte/1208572 to your computer and use it in GitHub Desktop.
A file I deleted that I had to retype quickly.
int num[256] = {0};
vector<string>::iterator iter = text.begin();
while (iter != text.end()){
string st = *iter;
for (int i = 0; i < st.size(); i++){
int pos = st[i];
num[pos]++;
}
}
vector<int> index;
int max = num[0];
index.push_back(0);
for (int i = 1; i < 256; i++){
if (i == ' ') continue;
if (num[i] > max){
index.clear();
max = num[i];
index.push_back(i);
}else if (num[i] == max){
index.push_back(i);
}
}
string res = "";
int value;
vector<int>::iterator iter2 = index.begin();
while (iter2 != index.end()){
value = *iter2;
res += (char)value;
iter2++;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment