So I am given a string:

x = "llo";

I have a string array with a list of words:

words{}={"hi", "bye", "lol"};

I have to compare x to each of the strings in the array to determine what x is if it is 'unscrambled'.

What is the best possible way to do this?

Edited by elitedragoon: n/a

8 Years
Discussion Span
Last Post by StuXYZ

The "best" algorithm depends on the nature of the input and the evaluation metric for "best". Is it only one x that will be compared etc.

It sounds like you have words at compile time. If that is the case, then use template meta-programming and create an alphabetical list of alphabetical entries to search against. Use the boost::mpl http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/index.html to do that and then use runtime polymorphism to find your target set. That would be very very fast (CPU) time.

Sorry for the useless reply but you haven't shown much effort with your question. What have your thought of and why do you like and more importantly why don't you like what you have prototyped/coded?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.