Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串

 A. Mike and Fax

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/548/problem/A

Description

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.

Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串

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 kpalindromes of the same length.

Input

The first line of input contains string s containing lowercase English 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.

Sample Input

saba
2

Sample Output

NO

HINT

题意

给你个字符串,告诉你这个字符串是由k个相同长度的回文串构成的,判断是否正确

题解:

数据范围很小,暴力判断就好了

 #include<bits/stdc++.h>
using namespace std; int main() {
string str;
int k,n;
int id;
cin>>str>>k;
/**如果恰没有k个的时候是输出NO 没考虑这个条件一直wa*/
if(str.length()%k != ) {
cout<<"NO"<<endl;
return ;
}
n = str.length()/k;
bool ans = false;
/**分成K组进行判断 如果有一组不满足回文串条件 则确定输出NO*/
for(int i = ; i <= k; i++) {
int bi = (i-)*n;
int ei = i*n-;
while(bi <= ei) {
if(str[bi] != str[ei]) {
ans = true;
break;
}
ei--;
bi++;
}
if(ans) break;
}
if(ans) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
上一篇:Can't use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it.


下一篇:HTML5的File API读取文件信息