博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round 56-B. Letters Rearranging(思维)
阅读量:4465 次
发布时间:2019-06-08

本文共 1751 字,大约阅读时间需要 5 分钟。

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string ss consisting only of lowercase Latin letters.

You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.

Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.

You have to answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — number of queries.

Each of the next tt lines contains one string. The ii-th line contains a string sisi consisting only of lowercase Latin letter. It is guaranteed that the length of sisi is from 11 to 10001000 (inclusive).

Output

Print tt lines. In the ii-th line print the answer to the ii-th query: -1 if it is impossible to obtain a good string by rearranging the letters of sisiand any good string which can be obtained from the given one (by rearranging the letters) otherwise.

Example

input

Copy

3aaabacabaxdd

output

Copy

-1abaacbaxdd

Note

In the first query we cannot rearrange letters to obtain a good string.

Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".

In the third query we can do nothing to obtain a good string.

题解:排个序看是否是回文串即可

代码:

#include
#include
#include
#include
using namespace std;int main(){ int n; cin>>n; char s1[1005]; for(int t=0;t

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781920.html

你可能感兴趣的文章
Guangsoushensou 2
查看>>
Java Metrics
查看>>
ftk学习记(对话框篇)
查看>>
POJ2676 Sudoku [数独]
查看>>
XMLHTTP使用具体解释
查看>>
[ACM] hdu 1003 Max Sum(最大子段和模型)
查看>>
337. House Robber III
查看>>
[ZJOI2007]矩阵游戏【bzoj1059/洛谷1129】/ [HEOI2016/TJOI2016]游戏
查看>>
java中final关键字
查看>>
Excel2010笔记
查看>>
牛客网NOIP赛前集训营-普及组
查看>>
BNUOJ 3278 Candies
查看>>
POJ 1251 Jungle Roads
查看>>
POJ 3680 Intervals
查看>>
TypeScript设计模式之工厂
查看>>
JS相关基础
查看>>
常用的网站链接
查看>>
算法复习——后缀自动机
查看>>
高并发大流量专题---2、流量优化(防盗链处理)
查看>>
html5--select与HTML5新增的datalist元素
查看>>