Educational Codeforces Round 56—B. Letters Rearranging

传送门

也是签到题

只要不是全为一种字符,显然都可以凑出满足条件

然后的直接 s o r t sort 一下就能满足了

#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
	char ch=getchar();
	int res=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
	return res;
}
int n;
char a[1005];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",a+1);
		int len=strlen(a+1);
		bool flag=false;
		for(int j=1;j<len;j++){
			if(a[j]!=a[j+1]){
				flag=true;break;
			}
		}
		if(!flag)cout<<"-1"<<'\n';
		else{
			sort(a+1,a+len+1);
			cout<<a+1<<'\n';
		}
	}
} 

猜你喜欢

转载自blog.csdn.net/qq_42555009/article/details/85023308