Created
September 10, 2011 17:51
-
-
Save mejibyte/1208572 to your computer and use it in GitHub Desktop.
A file I deleted that I had to retype quickly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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