UVA-10716Evil Straw Warts Live
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status Description Problem D:evil Straw warts Livea palindrome is a string of symbols which 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 both adjacent symbols. For example, the string "Mamad" is transformed to the palindrome "Madam" with 3 swaps:
- Swap "ad" to yield "MAMDA"
- Swap "MD" to yield "MADMA"
- Swap "Ma" to yield "madam"
The first line of input gives n, the number of test cases. For each test case, the one line of input follows, containing a string of lowercase letters. Output consists of one line per test case. This line would contain the number of swaps, or "impossible" if it is not possible to transform the input to a palindrome. Sample Input3mamadasflkjaabb Output for Sample Input3impossible2 Gordon v. CormackSource Root:: AOAPC i:beginning Algorithm Contests--Training Guide (Rujia Liu):: Chapter 1. Algorithm Design:: General Problem Solving Techniques:: exercises:intermediate Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 4. Algorithm Design Root:: Prominent problemsetters:: Gordon v. CormackSubmit Status |
Give a string to see if the string can form a palindrome string, if it can output the number of times you need to exchange letters, otherwise the output impossible
AC Code:
Uva-10716-evil Straw Warts Live (simple simulation)