判断回文串的程序,注意每个串的长度要求一致。然后一个串一个串的检查是不是回文串就好了。
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<string.h>
using namespace std;
char s[2000];
int main()
{
int n;
cin>>s>>n;
int len = strlen(s);
if( len % n != 0)
{
cout<<"NO"<<endl;
return 0;
}
int j = 0;
for(int i = 0 ; i < n; i++ )
{
for(int k = 0; k < len / n ; k++)
{
if(s[j+k] != s[j + (len / n) -1 -k])
{
cout<<"NO"<<endl;
return 0;
}
}
j+=len / n;
}
cout<<"YES"<<endl;
return 0;
}