#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char str[111];
int num[30];
int solve( int len)
{
int ans = 0;
for( int i = 0 ; i < len/2; i++)
{
int j = len - 1 - i;
int p, q;
if(str[i] == str[j])
continue;
for( q = j; str[i] != str[q] && q >= 0; q--);
for( p = i; str[j] != str[p] && p < len; p++);
if( p - i <= j - q)
{
ans += p - i;
for( int k = p; k > i; k--)
str[k] = str[k-1];
//cout<<str<<endl;
}
else
{
ans += j- q;
for( int k = q ; k < j; k++)
str[k] = str[k+1];
//cout<<<<str<<endl;
}
}
cout<<ans<<endl;
}
int main()
{
int n;
scanf("%d",&n);
getchar();
while (n--)
{
memset(num, 0, sizeof(num));
gets(str);
int len = strlen(str);
int odd_num = 0;
for(int j = 0; j < len; j++)
{
num[str[j] -'a'] ++;
if(num[str[j] -'a'] % 2)
odd_num ++;
else
odd_num --;
}
if(odd_num > 1)
printf("Impossible\n");
else
{
solve(len);
}
}
}
UVA 10716
最新推荐文章于 2018-12-22 16:38:00 发布