#K43032. Minimum Operations to Make a Palindrome
Minimum Operations to Make a Palindrome
Minimum Operations to Make a Palindrome
Given a string s of length n, a palindrome is a string that reads the same forward and backward. In one operation you can change a character in the string. The goal is to determine the minimum number of operations required to convert the string into a palindrome. Mathematically, if we define the cost for a string s as
\[ cost(s) = \sum_{i=1}^{\lfloor n/2 \rfloor} \mathbf{1}\{s_i \neq s_{n-i+1}\} \]
where \(\mathbf{1}\{condition\}\) is 1 if the condition is true and 0 otherwise, then you need to compute cost(s) for each test case.
Input will be provided as follows: the first line contains the number of test cases T. Each of the following T lines contains a single string. For each string, you should output the minimum number of operations needed to transform it into a palindrome.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- An integer T which indicates the number of test cases.
- T lines follow, each containing a single string.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of operations required to make the given string a palindrome.
## sample3
abc
aaa
abca
1
0
1
</p>