Educational Codeforces Round 56 (Rated for Div. 2) CodeForces - 1093B

题意:

给你一个字符串,任意变化,使它变成不是回文串,如果不行,就输出-1

我的做法是,如果这个串只有同一个字母,那么直接输出-1

否则,sort一下,输出就行了,即可保证不是回文串

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =1000+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
char s[maxn];

int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		int cnt=0;
		scanf("%s",s);
		int len=strlen(s);
		for(int i=0;i<len-1;i++)
		{
			if(s[i]==s[i+1]) cnt++;
		}
		if(cnt==len-1) printf("-1\n");
		else
		{
			sort(s,s+len);
			for(int i=0;i<len;i++) printf("%c",s[i]);
			printf("\n");
		}
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/85040913