Evil Straw Warts Live (简单模拟)

Problem D: Evil Straw Warts LiveA palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, compute the number of swaps necessary to transform the string into a palindrome. Byswapwe mean reversing the order of two adjacent symbols. For example, the string "mamad" may be transformed into the palindrome "madam" with 3 swaps:

The first line of input givesn, the number of test cases. For each test case, one line of input follows, containing a string of up to 100 lowercase letters. Output consists of one line per test case. This line will contain the number of swaps, or "Impossible" if it is not possible to transform the input to a palindrome.

Sample Input3mamadasflkjaabbOutput for Sample Input3Impossible2Gordon V. Cormack

,与其临渊羡鱼,不如退而结网。

Evil Straw Warts Live (简单模拟)

相关文章:

你感兴趣的文章:

标签云: