Codeforces Round 56-B. Letters Rearranging(思维)
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
3
aa
abacaba
xdd
output
Copy
-1
abaacba
xdd
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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n;
cin>>n;
char s1[1005];
for(int t=0;t<n;t++)
{
scanf("%s",s1);
sort(s1,s1+strlen(s1));
int cnt=0;
for(int j=1;j<strlen(s1);j++)
{
if(s1[j]==s1[j-1])
{
cnt++;
}
}
if(cnt==strlen(s1)-1)
{
printf("-1\n");
}
else
{
puts(s1);
}
}
return 0;
}
Codeforces Round 56-B. Letters Rearranging(思维)的更多相关文章
- Educational Codeforces Round 56 (Rated for Div. 2) ABCD
题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...
- Educational Codeforces Round 56 (Rated for Div. 2)
涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...
- Educational Codeforces Round 56 Solution
A. Dice Rolling 签到. #include <bits/stdc++.h> using namespace std; int t, n; int main() { scanf ...
- Educational Codeforces Round 40 C. Matrix Walk( 思维)
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #452 F. Letters Removing
Description Petya has a string of length n consisting of small and large English letters and digits. ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
随机推荐
- Redis常用数据结构和操作
1.String 存入字符类型 Set name luowen 设置name = luowen 存储 Get name 获取设置好的name的值 Setnx name luowen 设置name键值为 ...
- 理解多线程中的ManualResetEvent(C#)
线程是程序中的控制流程的封装.你可能已经习惯于写单线程程序,也就是,程序在它们的代码中一次只在一条路中执行.如果你多弄几个线程的话,代码运行可能会更加“同步”.在一个有着多线程的典型进程中,零个或更多 ...
- leetcode 23. Merge k Sorted Lists(堆||分治法)
Merge k sorted linked lists and return it as one sorted list. 题意:把k个已经排好序的链表整合到一个链表中,并且这个链表是排了序的. 题解 ...
- 时尚与深度学习系列:Fashion forward: Forecasting visual style in fashion
https://arxiv.org/pdf/1705.06394.pdf 将深度学习与时尚预测联系在一起,是一个很有趣但是估计结果会没什么成效的话题.因为,时尚预测这一领 ...
- HDU5875Function(单调队列)
The shorter, the simpler. With this problem, you should be convinced of this truth. You are giv ...
- 递归------python实现列表创建二叉树
# -*- coding:utf-8 -*- '二叉树结点类' class TreeNode: def __init__(self, x): self.val = x self.left = None ...
- POJ2481(树状数组:统计数字 出现个数)
Cows Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 15405 Accepted: 5133 Description ...
- 绝对路径VS相对路径
绝对路径:不必赘述,就是从盘符开始写直到找到你所需要的文件为止,把所有的目录写完整即可.但是在做网站的时候绝对不推荐用绝对路径,因为不可能服务器中的路径和在做设计时候所用的电脑的路径一致,也不可能说在 ...
- MAF框架的使用限制
虽然MAF实现了插件式开发,动态热插拨,AppDomain隔离等诸多优点,但是正因为它复杂的功能机制也带来了很多其它方面的使用限制,下面列出官方给出的MAF框架的使用限制. 1) 在应用主程序显示的插 ...
- 使用Axis2方式发布webService的三种方式
1.Axis2的下载和安装 首先可以下载如下两个zip包:axis2-1.6.1-bin.zipaxis2-1.6.1-war.zip其中 axis2-1.6.1-bin.zip文件中包含了Axis2 ...