Uva-10716-evil Straw Warts Live (simple simulation)

Source: Internet
Author: User

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 Input
3mamadasflkjaabb
Output for Sample Input
3impossible2
Gordon v. Cormack

Source

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. Cormack

Submit 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.