I am trying to create a program that reads a sentence, such as: "abba is running to the radar" scans this sentence, and then prints out all the palindromes. I am running into issues with my arrays and for statements.
Here is my code:
I am aware that there is a few "useless" variables in there at the moment, I will clean them up (as well as some useless statements, I see those too). The issue comes at about line 17. The variable backwards REMOVES all the spaces from the array, so when it comes time to compare the strings, it is comparing individual words to the ENTIRE string, thus no words will ever be a palindrome.
I realise the problem, I just need a small hint on what I could to fix it? Thanks for any help.
It will append a space between the words. Now to selectively append the space you would have to tell us more about when you need to append the space. You can try out a simple program on just appending strings and then once you are clear with that you can incorporate your findings in this large program.
Its good to isolate and solve the problem rather than solving it as part of another larger problem.
While you are appending the space between the words you need to make sure that you dont append the space after the last word, because you need spacing only between the words.
I discovered, that palindromes could be a few different types: original sentences with no changes, single words, and sentences with removed delimiters.
So, actually there are few scenarios you need to pay attention on.
Anyway, i got my solution. So what is yours?
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop