zoukankan      html  css  js  c++  java
  • CF 548A

    A. Mike and Fax
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 test(s)
    input
    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
    output
    NO
    input
    saddastavvat
    2
    output
    YES
    Note

    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 

  • 相关阅读:
    [LeetCode] 101. Symmetric Tree 对称树
    [LeetCode] 202. Happy Number 快乐数
    Windows任务计划创建计划,定时执行PowerShell命令
    读经典——《CLR via C#》(Jeffrey Richter著) 笔记_IL和验证
    读经典——《CLR via C#》(Jeffrey Richter著) 笔记_方法执行
    吐槽自己
    读经典——《CLR via C#》(Jeffrey Richter著) 笔记_元数据
    读经典——《CLR via C#》(Jeffrey Richter著) 笔记_CLR
    设置IIS,使客户端访问服务器上的文件
    SQL语句 ANSI_NULLS 值(ON|OFF)的含义
  • 原文地址:https://www.cnblogs.com/111qqz/p/4534631.html
Copyright © 2011-2022 走看看