#C10055. Palindrome Rearrangement
Palindrome Rearrangement
Palindrome Rearrangement
Given a string s
containing only lowercase alphabetical characters, determine whether its characters can be rearranged to form a palindrome.
A palindrome is a string that reads the same backward as forward. A necessary and sufficient condition for a string to be rearranged into a palindrome is that at most one character occurs an odd number of times. In other words, if we let \( f(c) \) be the frequency of character \( c \) in s
, then the string can form a palindrome if:
\( \#\{c : f(c) \% 2 \neq 0\} \leq 1 \)
For example:
s = "civic"
can be rearranged into "civic" which is a palindrome.s = "ivicc"
can be rearranged into "civic" which is a palindrome.s = "hello"
cannot be rearranged into any palindrome.
Your task is to implement a solution that reads the input string from standard input and prints True
if the string can be rearranged to form a palindrome and False
otherwise.
inputFormat
The input consists of a single line containing a string s
composed of lowercase alphabetical characters.
Example:
civic
outputFormat
Output a single line: True
if the string can be rearranged into a palindrome, or False
otherwise.
Example:
True## sample
civic
True