zoukankan      html  css  js  c++  java
  • 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门

     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 }
    编译人生,运行世界!
  • 相关阅读:
    CKA&CKAD考试
    进程线程和协程
    HTTP协议
    Centos操作系统启动流程
    高并发下的Linux内核参数优化
    DDoS防护系统建设的一些思路
    DDoS防护实现概述
    Nginx故障排查思路
    git常用指令集
    DNS实现粗粒度容灾
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4534178.html
Copyright © 2011-2022 走看看