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]之间,并且数组全 ...
随机推荐
- vs2015professional过期后登录微软账户仍然不能使用的解决方法
今天安装了vs2015pro版,找到了一个可以正常使用的密钥 2015 pro(专业版)key:HMGNV-WCYXV-X7G9W-YCX63-B98R2 注意是专业版,非企业版 来源:https:/ ...
- css书写规则
无规矩不成方圆,不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的 不要在自闭合(self-closing)元素的尾部添加斜线 不要省略可选的结束标签(closing tag)(例 ...
- HihoCoder1672 : 区间问题([Offer收割]编程练习赛41)(贪心)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定N个区间[Ai, Bi],请你找到包含元素最少的整数集合S,使得每个区间都至少有两个整数在S中. 例如给定三个区间[1 ...
- ACM学习历程—HDU 5326 Work(树形递推)
Problem Description It’s an interesting experience to move from ICPC to work, end my college life an ...
- .NETFramework:Random
ylbtech-.NETFramework:Random 1.程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c ...
- 浅析C语言中strtol()函数与strtoul()函数的用法
转自:http://www.jb51.net/article/71463.htm C语言strtol()函数:将字符串转换成long(长整型数) 头文件: ? 1 #include <stdli ...
- ACM实用C语言函数
函数名: abs 功 能: 求整数的绝对值 用 法: int abs(int i); 程序例: #include <stdio.h> #include <math.h> int ...
- 如何在模板类中使用这些point类型?
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=271 由于PCL模块较多,并且是一个模板库,在一个源文件里包含很多PCL算法 ...
- Ubuntu Navicat for&nbs…
首先上官网上下载LINUX版本: http://www.navicat.com/download 1. 下载 navicat110_mysql_en.tar.gz 文件 2. 下载后解压tar文件 t ...
- linux 下定位程序假死
ps -ef | grep 程序名称 pstack 程序的进程ID