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]之间,并且数组全 ...
随机推荐
- 杂草丛生HTML5网站模板
杂草丛生HTML5个人网站模板是一款野草到处生长的HTML5网站模板下载. 模板地址:http://www.huiyi8.com/sc/8780.html
- BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...
- 常用JS组件整理
1.漂亮的弹出层----artDialog http://aui.github.io/artDialog/ 2.弹出层 ------layer http://sentsin.com/jquery/la ...
- 15 个最佳的 jQuery 布局插件【转】
英文原文:15 Best jQuery Grid Plugins for Developers 现如今,网站开发设计的需求会要求自动适应所有移动设备,即响应式网站: 在开发网站时必须考虑对平板设备融合 ...
- python3 - 商品管理的程序,商品信息都存在一个json串里面
商品管理的程序,商品信息都存在一个json串里面 1.查询商品信息 #校验商品是否存在 2.新增商品 # #校验商品是否存在 #校验价格是否合法 3.修改商品信息 ##校验商品是否存在 if chic ...
- Mysql处理字符串函数(转)
http://www.jb51.net/article/27458.htm 感觉上MySQL的字符串函数截取字符,比用程序截取(如PHP或JAVA)来得强大,所以在这里做一个记录,希望对大家有用. 函 ...
- 每天一个linux命令(3):cd命令
版权声明 更新:2017-04-27博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下命令cd. 2 开 ...
- JAVA,MYSQL,ORACLE的数据类型对比
MySQL Data Type Oracle Data Type Java BIGINT NUMBER(19, 0) java.lang.Long BIT RAW byte[] BLOB BLOB, ...
- sulime的必备插件
常用插件 : SideBarEnhancements HTML-CSS-JS Prettify BracketHighlighter SublimeCodeIntel Emmet CTags Mark ...
- ElementRef, @ViewChild & Renderer
ElementRef: In Angular2 Doc, it suggest to "avoid" using ElementRef. It access DOM directl ...