Hide
Evil Straw Warts Live

-
swap “ad” to yield “mamda”
-
swap “md” to yield “madma”
-
swap “ma” to yield “madam”
Input
The first line of input gives $1 \le n \le 200$, the number of test cases. For each test case, one line of input follows, containing a string of up to $100$ lowercase letters.
Output
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 Input 1 | Sample Output 1 |
---|---|
3 mamad asflkj aabb |
3 Impossible 2 |
CPU Time limit
1 second
Memory limit
1024 MB
Statistics
Show
Downloads
Author
Gordon V. Cormack
Source
Waterloo Programming Contest 2004-09-19