码迷,mamicode.com
首页 > 其他好文 > 详细

字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

时间:2015-05-27 20:35:41      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     字符串处理:回文串是串联的,一个一个判断
 3 */
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 #include <string>
 9 using namespace std;
10 
11 const int MAXN = 1e3 + 10;
12 const int INF = 0x3f3f3f3f;
13 char s[MAXN];
14 
15 bool check(int x, int y)
16 {
17     for (int i=x, j=y; i<j; ++i, --j)
18     {
19         if (s[i] != s[j])    return false;
20     }
21 
22     return true;
23 }
24 
25 int main(void)        //Codeforces Round #305 (Div. 2) A. Mike and Fax
26 {
27     int k;
28     while (scanf ("%s", s) == 1)
29     {
30         scanf ("%d", &k);
31         int len = strlen (s);
32         if (len % k != 0)    puts ("NO");
33         else if (len == 1 && k == 1)    puts ("YES");
34         else
35         {
36             int m = len / k;    bool flag = true;
37             for (int i=0; i<len; i+=m)
38             {
39                 if (!check (i, i+m-1))
40                 {
41                     flag = false;    break;
42                 }
43             }
44             if (flag)    puts ("YES");
45             else    puts ("NO");
46         }
47     }
48 
49     return 0;
50 }

 

字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4534178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!