#C29. Filter Palindromes
Filter Palindromes
Filter Palindromes
Given a list of strings, your task is to filter out and print only the strings that are palindromes. A string is considered a palindrome if it reads the same forward and backward. For instance, radar
is a palindrome, while hello
is not.
The input begins with an integer n representing the number of strings, followed by n lines each containing a string. Your goal is to output the palindrome strings in the order they appear, separated by a single space. If there are no palindromes, output an empty line.
Recall that a string \(s\) is a palindrome if \(s = s^R\), where \(s^R\) is the reverse of \(s\).
inputFormat
The input is provided via standard input (stdin) and has the following format:
- The first line contains an integer n, the number of strings.
- The next n lines each contain a single string.
outputFormat
Output a single line to standard output (stdout) containing all the palindrome strings separated by a single space. If no palindromes exist in the input, output an empty line.
## sample5
radar
hello
level
world
deified
radar level deified
</p>