题解:P12592 重生有惊喜
chenxiangjun · · 题解
题意:
给你一个字符串让你判断是否能交换若干次变成回文串。
思路:
由于对此次数没要求我们就可以先不管原串如何,就直接判断字符串是否能成功成为回文串。
证明:
由于是可以将一个字符丢来丢去于是就是可以有原串任意排列,相当于以上的思路。
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100500;
int t,a[N],n;
string as;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>as;
n=as.length();
as=' '+as;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
{
a[as[i]]++;
}
int f=0;
for(int i=1;i<=200;i++)
{
if(a[i]%2!=0)
{
f++;
}
}
if(f<=n%2)
{
cout<<"Yes\n";
}
else
{
cout<<"No\n";
}
}
return 0;
}