#C5941. Palindromic Rearrangement
Palindromic Rearrangement
Palindromic Rearrangement
You are given a string s
consisting of lowercase English letters. Your task is to determine if its characters can be rearranged to form a palindrome.
A palindrome is a string that reads the same backward as forward. In order for a string to be rearranged into a palindrome, at most one character can have an odd frequency. In other words, if we denote by \(f(c)\) the frequency of character \(c\), then the condition is:
\(\sum_{c \in s} \left[ f(c) \bmod 2 \neq 0 \right] \leq 1\)
For example, consider the string "carrace". By rearranging it, we can form "racecar", which is a palindrome. However, the string "hello" cannot be rearranged to form a palindrome.
Input and output should be handled via stdin and stdout.
inputFormat
The input consists of a single line containing a non-empty string s
of lowercase English letters.
outputFormat
Output a single line containing either True
or False
. Print True
if the characters of the string can be rearranged to form a palindrome, and False
otherwise.
carrace
True