Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created May 2, 2015 17:26
Show Gist options
  • Save krysseltillada/c2a7ce95ffdc6e5dd711 to your computer and use it in GitHub Desktop.
Save krysseltillada/c2a7ce95ffdc6e5dd711 to your computer and use it in GitHub Desktop.
most words detector
#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