#C12068. Reverse and Remove Palindromes

    ID: 41454 Type: Default 1000ms 256MiB

Reverse and Remove Palindromes

Reverse and Remove Palindromes

Given a list of words, your task is to reverse each word that is not a palindrome and remove those that are palindromic. A word is considered a palindrome if it reads the same backward as forward (i.e. s=sRs = s^R). The order of the words must remain the same. Output the reversed non-palindromic words on the first line (space-separated) and the palindromic words on the second line (space-separated). If there are no words in a category, output an empty line for that category.

inputFormat

The input is read from standard input and follows this format:\nThe first line contains an integer nn, representing the number of words. Each of the following nn lines contains a single word.

outputFormat

Print two lines on standard output:\n- The first line should contain the reversed versions of the non-palindromic words, separated by spaces.\n- The second line should contain the palindromic words (in their original order), separated by spaces.\nIf a list is empty, print an empty line for that list.## sample

4
racecar
hello
madam
world
olleh dlrow

racecar madam

</p>