Palindromic Distance
시간 제한1초메모리 제한2048 MB
주어진 단어를 어떤 팰린드롬으로 바꾸는 데 필요한 삽입, 삭제, 치환의 최소 횟수를 각 테스트마다 구한다.
문제
The edit distance between two strings and is the minimum number of edit operations that turns into . There are three edit operations that can be applied to a string: Insert a character, delete a character, and substitute some character by a different one.
For example, we can turn hello into world with four substitutions, so the edit distance is at most . You can turn wally into walter with two substitutions and one insertion, so the edit distance is at most . Computing the edit distance between two strings is a well-known problem with many applications.
The task at hand is to compute the edit distance of a string to one of the closest palindromes. A palindrome is a string that is the same when read backwards, for example madam.
The edit distance of hello to the closest palindrome is only : We can turn hello into ollo, or hllh, or elle with two edit operations.
Write a program that can find the distance of a word to a closest palindrome.
입력
Each test contains multiple test cases. The first line contains the number of test cases . The description of the test cases follows.
The only line of each test case contains a word consisting only of lowercase letters.
출력
For each test case, output the edit distance of the input word to its closest palindrome.
제한
- The word has length at least one.
- It is guaranteed that the sum of the lengths of the words over all test cases does not exceed .