It's been so long since I've visited lebgeeks! Now the questions look easier :)
Here's my answer in C++11:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
int main() {
int points = 0;
int most_annoying_word_points = 0;
std::vector<std::string> most_annoying_words;
// Mapping letters to keys
std::map<char, int> dumbphone = {
{ 'a', 2 },
{ 'b', 2 },
{ 'c', 2 },
{ 'd', 3 },
{ 'e', 3 },
{ 'f', 3 },
{ 'g', 4 },
{ 'h', 4 },
{ 'i', 4 },
{ 'j', 5 },
{ 'k', 5 },
{ 'l', 5 },
{ 'm', 6 },
{ 'n', 6 },
{ 'o', 6 },
{ 'p', 7 },
{ 'q', 7 },
{ 'r', 7 },
{ 's', 7 },
{ 't', 8 },
{ 'u', 8 },
{ 'v', 8 },
{ 'w', 9 },
{ 'x', 9 },
{ 'y', 9 },
{ 'z', 9 }
};
// check for each word
std::string word;
// Open dictionary
std::ifstream dict("/usr/share/dict/words");
// Check if dictionary is found
if (dict.is_open()) {
// For each word
while (getline(dict, word)) {
// Reset number of points for every word
points = 0;
// Loop through all letters of a word
for (int i = 1; i < word.length(); i++)
// If the next letter is not a small letter, discard the word an start with the next one
if ( ! (word.at(i-1) >= 97 && word.at(i-1) <= 122) ) {
points = 0;
break;
}
// Otherwise, compare it with the following letter to see if the same key needs to be pressed
else if (dumbphone[word.at(i-1)] == dumbphone[word.at(i)])
points++;
// If word has the most points, then remove all previous annoying words and add this one to the list
if (points > most_annoying_word_points) {
most_annoying_words.clear();
most_annoying_word_points = points;
most_annoying_words.push_back(word);
}
// Add to most annoying words if points matches current most annoying word
else if (points == most_annoying_word_points)
most_annoying_words.push_back(word);
}
// Print the most annoying words
std::cout << "The most annoying words are" << std::endl << std::endl;
for (int i = 0; i < most_annoying_words.size(); i++)
std::cout << most_annoying_words[i] << std::endl;
std::cout << std::endl << "With " << most_annoying_word_points << " points each " << std::endl;
// Close dictionary
dict.close();
}
else
std::cout << "Unable to open file" << std::endl;
return 0;
}
Here's the output:
"The most annoying words are
accommodated
accommodation
accommodations
cannonaded
cannonball
cannonballs
decommissioned
highlighted
highlighters
monotonically
moonlighted
moonlighters
noncommittally
nondenominational
nonprofessional
nonprofessionals
professorships
With 6 points each"
By points I mean the number of waits. I've used the dictionary /usr/share/dict/words on Linux, it would be great if someone could verify the answer. Cheers!