#C7432. Anagram Palindrome Checker
Anagram Palindrome Checker
Anagram Palindrome Checker
Given a string s
, determine whether any permutation (anagram) of the string can form a palindrome.
A palindrome is a string that reads the same forwards and backwards. For a string to be able to be rearranged into a palindrome, the frequency of each character must meet the condition:
$$\text{At most one character can have an odd frequency count.}$$
For example, for the string carrace
, the frequency count is:
- c : 2
- a : 2
- r : 2
- e : 1
Since only one character has an odd count, it can be rearranged as racecar
, which is a palindrome. Your task is to implement a program that reads a string from stdin
and prints True
if the string is an anagram of a palindrome, and False
otherwise.
inputFormat
The input consists of a single line containing a string s
. The string may be empty.
outputFormat
Output a single line: True
if the input string can be rearranged to form a palindrome; otherwise, output False
.
carrace
True