Description
While Mike is walking in the subway and all of the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.
He is not a sure if this is his own back-bag or someone else ' s. He remembered that there were exactly K messages in his own bag, each is a palindrome string and all tho SE strings had the same length.
He asked him and tell him if he had worn his own back-bag. Check if the given string s is a concatenation of K palindromes of the same length.
Input
The first line of input contains string s containing lowercase 中文版 letters (1≤| S| ≤1000).
The second line contains integer k (1≤ k ≤1000).
Output
Print "YES" (without quotes) if he has worn his own back-bag or "NO" (without quotes) otherwise.
Examples
input
Saba
2
Output
NO
input
Saddastavvat
2
Output
YES
First of all, the length can not be divisible, of course, not meet the requirements. Then we split the string according to the requirements, and judged if it was a palindrome.
#include <iostream> #include <stdio.h> #include <string.h>using namespace Std;int main () { string s; int n; cin>>s; cin>>n; if (S.length ()%n) { cout<< "NO" <<endl; } else { int i,j; int mid=s.length ()/n; for (i=0;i<n;i++) { string ss=s.substr (I*mid,mid); for (int j=0;j<=ss.length ()/2;j++) { if (ss[j]!=ss[ss.length () -1-j]) { cout<< "NO" <<endl; return 0; } } cout<<ss<<endl; } cout<< "YES" <<endl; } return 0;}
Codeforces Round #305 (Div. 2) A