#K4651. Minimum Cost to Palindrome
Minimum Cost to Palindrome
Minimum Cost to Palindrome
You are given a string s
. Your task is to determine the minimum number of character replacements required to convert the string into a palindrome. A palindrome is a string that reads the same forward and backward. In each replacement, you can change one character to any other character.
The cost is defined as the number of replacements you need to make. For example, for the string \(s = \texttt{abca}\), you only need to replace one character (the second character 'b' or the third character 'c') to obtain a palindrome.
Input/Output Specifications:
- Input: A single string
s
read from standard input. - Output: An integer representing the minimum number of replacements required to convert
s
into a palindrome, printed to standard output.
Note: If the string is already a palindrome, the cost is 0.
inputFormat
The input consists of a single line containing a non-empty string s
comprised of lowercase letters.
outputFormat
Output a single integer which is the minimum number of character replacements required to convert the given string into a palindrome.## sample
a
0