#C1787. String Analysis: Palindrome and Rearrangement Check
String Analysis: Palindrome and Rearrangement Check
String Analysis: Palindrome and Rearrangement Check
You are given a string \(S\) and your task is to analyze it according to the following criteria:
- Determine whether \(S\) contains at least one space.
- Check if \(S\) is a palindrome. In doing so, you should ignore spaces, punctuation, and case. Formally, let \(S'\) be the string obtained by removing all non-alphanumeric characters from \(S\) and converting the result to lowercase. Then, \(S\) is a palindrome if \(S' = \text{reverse}(S')\).
- Determine whether the characters of \(S\) can be rearranged to form a palindrome. That is, using the cleaned string \(S'\) as defined above, check if at most one character in \(S'\) has an odd frequency.
For example, given the input A man a plan a canal Panama
, after cleaning the string becomes amanaplanacanalpanama
, which is a palindrome. Also, its characters can obviously be rearranged into a palindrome. Your program should output three boolean values corresponding to these checks.
inputFormat
The input is read from stdin
and consists of a single line representing the string \(S\). The string may contain spaces, punctuation, and a mix of uppercase and lowercase letters.
outputFormat
Output three lines to stdout
. Each line should contain either True
or False
(without quotes):
- The first line indicates whether the original string contains any spaces.
- The second line indicates whether the cleaned string is a palindrome.
- The third line indicates whether the characters of the cleaned string can be rearranged to form a palindrome.
A man a plan a canal Panama
True
True
True
</p>