Created
May 2, 2015 17:26
-
-
Save krysseltillada/c2a7ce95ffdc6e5dd711 to your computer and use it in GitHub Desktop.
most words detector
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
#include <algorithm> | |
#include <vector> | |
#include <string> | |
#include <iostream> | |
#include <numeric> | |
using namespace std; | |
int main() | |
{ | |
vector<string> words; | |
unsigned int count = 0; | |
int counter1 = 0 ,counter2 = 0, count1 = 0, count2 = 0; | |
string input = "none", in, mode, compare; | |
cout << "enter a strings: "; | |
getline(cin, input); | |
while (count < input.length()){ | |
in = in + input[count]; | |
if (input[count] == ' ') { | |
words.push_back(in); | |
in = ""; | |
} | |
count++; | |
} | |
sort(words.begin(), words.end()); | |
compare = words[0]; | |
for (int n = 0; n < words.size(); n++){ | |
if (compare == words[n]){ | |
count1++; | |
} | |
else{ | |
if (count1 > count2){ | |
count2 = count1; | |
count1 = 0; | |
mode = words[n-1]; | |
compare = words[n]; | |
} | |
else{ | |
mode = mode; | |
} | |
} | |
} | |
cout << "most entered words: " << mode << endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment