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.
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.
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
题解:
题目意思就是给你一个字符串,判断由K个长度相同的回文串组成,是否正确
直接暴力判断就好了
//llm #include<stdio.h> #include<string.h> #include<math.h> #define N 1005 char str[N]; int main() { int l,i,j,k,n,t,len,flag; while(scanf("%s",str)!=EOF) { flag=0; scanf("%d",&k); getchar(); len=strlen(str); n=len/k; //printf("%c %c\n",str[0],str[len-1]); if(k*n!=len) flag=1; else { for(i=0;i<len;i+=n) { l=i; j=i; while(i<j+n-1) { if(str[l]==str[j+n-1]) { l++; j--; } else { flag=1; break; } } } } if(flag==1) printf("NO\n"); else printf("YES\n"); } return 0; }