CF1093B.Letters Rearranging

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

给你一个仅由小写拉丁字母组成的字符串 ss。

你可以随意重新排列该字符串中的所有字母。你的任务是通过重新排列给定字符串的字母,得到一个“好”字符串;如果不可能做到,则报告无法实现。

我们称一个字符串为“好”字符串,当且仅当它不是回文串。回文串是指从左到右读与从右到左读完全相同的字符串。例如,字符串 "abacaba"、"aa" 和 "z" 是回文串,而字符串 "bba"、"xd" 不是。

你需要回答 tt 个相互独立的查询。

输入格式

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

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

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示查询次数。

接下来的 tt 行,每行包含一个字符串。其中第 ii 行包含一个字符串 sis_i,该字符串仅由小写拉丁字母组成。保证每个 sis_i 的长度在 11 到 10001000(含)之间。

输出格式

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 sis_i and any good string which can be obtained from the given one (by rearranging the letters) otherwise.

输出 tt 行。在第 ii 行中,输出第 ii 个查询的答案:若无法通过对字符串 sis_i 的字母重新排列得到一个“好”字符串,则输出 −1-1;否则,输出任意一个可通过重排给定字符串得到的“好”字符串。

输入输出样例

  • 输入#1

    3
    aa
    abacaba
    xdd

    输出#1

    -1
    abaacba
    xdd

说明/提示

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.

在第一个查询中,我们无法通过重新排列字母来得到一个好字符串。

第二个查询的其他(非全部)正确答案示例:“ababaca”、“abcabaa”、“baacaba”。

在第三个查询中,我们无法进行任何操作来得到一个好字符串。

输入解题思路,AI测评打分。不知道怎么写?

首页