Codeforces 1093B. Letters Rearranging

给若干字符串,问你能不能构成非回文串。
如果只有一种字符,肯定不能,否则肯定能。然后按从小到大的顺序依次输出就好啦

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int t,cnt[30],num;
char s[1010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>s;
		memset(cnt,0,sizeof(cnt)) ;
		num = 0;
		for(int i = 0;s[i];i++)	{
			if(!cnt[s[i]-'a']) num++;
			cnt[s[i]-'a']++; 
		}
		if(num == 1) cout<<-1<<endl;
		else{
			 for(int i = 0;i<30;i++)
			 	if(cnt[i]) for(int j = 0;j<cnt[i];j++)	cout<<char(i+'a');
			cout<<endl;
		}
	}
	return 0; 
} 

猜你喜欢

转载自blog.csdn.net/winhcc/article/details/85036415
今日推荐