C++ Riddle

1. ## C++ Riddle

Can anyone write a C++ program which asks the user to input a string and checks if any word in the string is a palindrome.....

eg... if the string is Dad i am riding kayak, the program must display...

Kayak

each word remember!!

?anticode?

2. I can't program any more, its been a long time, but it shouldn't be to hard to do. Just do something like....

while (more words)
cin << 1word
drow1 = reverse of word1
compare 1word & drow1
if same, print, else, goto next word.

3. Souleman is on the right path...

4. If you want one in Java, I'll be glad to edit my normal palindrome tester which I did for an AP Java class, now it tests entire sentences, here's the source below:

Code:
```/*
Dave T
Date: September 30, 2003
Page: 184 Problem 3.12

The Quote of the Day:
"Eat right, don't smoke, die anyway."
*/

import cs1.Keyboard;
import java.util.Random;
import java.util.StringTokenizer;
import java.text.NumberFormat;

public class PalindromeTester
{
public static void main (String[] args)
{
String str, another = "y", lower;
int left, right;

while (another.equalsIgnoreCase("y"))
{
System.out.println ("Enter a potential palindrome:");

lower = str.toLowerCase();

left = 0;
right = str.length() - 1;

while (lower.charAt(left) == ' ' || lower.charAt(left) == '.' || lower.charAt(left) == ',' || lower.charAt(left) == '?')
{left++;}
while (lower.charAt(right) == ' ' || lower.charAt(right) == '.' || lower.charAt(right) == ',' || lower.charAt(right) == '?')
{right--;}

while (lower.charAt(left) == lower.charAt(right) && left <= right)
{

left++;
right--;

while (lower.charAt(left) == ' ' || lower.charAt(left) == '.' || lower.charAt(left) == ',' || lower.charAt(left) == '?')
{left++;}
while (lower.charAt(right) == ' ' || lower.charAt(right) == '.' || lower.charAt(right) == ',' || lower.charAt(right) == '?')
{right--;}

}

System.out.println();

if (left < right)
System.out.println("That string is NOT a palindrome.");
else
System.out.println("That string IS a palindrome.");

System.out.println();
System.out.print("Test another palindrome (y/n)? ");
}
}
}```
I know I have a lot of useless classes being imported, but since I use an outline for every program thats been premade, I really don't delete any...

If it has to be in C++, drop me a line, I still remember of some of that stuff...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•