跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0543. Evil Straw Warts Live

    ID: 549 传统题 1000ms 128MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>字符串难度待定难度共享题库高校与竞赛共享题英文题面题目来源题面语言

Evil Straw Warts Live

题目描述

A 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. By swap we mean reversing the order of two adjacent symbols. For example, the string "mamad" may be transformed into 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, 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.

输入格式

Please Input Input Here

输出格式

Please Input Output Here

样例 1

输入

3
mamad
asflkj
aabb

输出

3
Impossible
2

题目来源:fps-zhblue-waterloo-040919.xml;FPS 共享题包,题包内第 4 题。保留原作者与原赛事署名。