While Mike was walking in the subway, all 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 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 was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).
The second line contains integer k (1 ≤ k ≤ 1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
saba
1 #include <algorithm> 2 #include <cstdio> 3 #include <iostream> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 #include <map> 8 9 using namespace std; 10 const int N=1E3+5; 11 char st[N]; 12 int k,len,ave; 13 bool ok(int l,int r) 14 { 15 for (int i = l ; i<=(l+r)/2;i++) 16 if (st[i]!=st[l+r-i]) 17 return false; 18 return true; 19 } 20 21 int main() 22 { 23 cin>>st; 24 cin>>k; 25 len = strlen(st); 26 ave= len/k; 27 if (k*ave!=len){cout<<"NO"<<endl;return 0;} 28 for (int i = 1 ; i<=k;i++ ) 29 { 30 if (!ok((i-1)*ave,i*ave-1)) 31 { 32 cout<<"NO"<<endl; 33 //cout<<i<<endl; 34 return 0; 35 } 36 37 } 38 cout<<"YES"<<endl; 39 40 41 42 return 0; 43 }
2
NO
saddastavvat
2
YES
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
水题。分割成K个,每个串判断是否回文,如果都是就yes,否则no
需要注意的是,可能不能正好分成长度相同的K个,这个时候也要No