Labdabeta 182 Posting Pro in Training Featured Poster

I still do not believe that is what is desired here. What seems to be the goal is some function like vector<string> getAllPalindromes(string str) that returns all palindromes in a string. So for example, getAllPalindromes("No lemon, no melon!") should return {"nolemonnomelon","olemonnomelo",...,"onno","nn"}.

As far as I can tell there is no more efficient way to do this than to loop letter by letter and check each substring for palindromes.

IE:

vector<string> getAllPalindromes(string str)
{
    vector<string> ret;
    for (int i=0; i<str.length(); ++i)
    {
        for (int ii=str.length()-1; ii>(i+1); --ii)//the i+1 is to eliminate 1 letter palindromes
        {
            if (isPalindrome(str.substr(i,ii)))
            {
                //add the string, and all its inner strings to ret
                //so "kayak" would add "kayak", and "aya" to ret
                i=ii;//skip ahead to the end of that sub-palindrome
                //break; the inner loop should break itself anyways.
            }
        }
    }
    return ret;
}
Labdabeta 182 Posting Pro in Training Featured Poster

This can be easily done with a loop:

int main()
{
    bool exit=false;
    while (!exit)
    {
        //CODE HERE!
        //somewhere have:
        /* if (user_want_to_quit)
                exit=true;
        */
    }
    return 0;
}