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 

  • 相关阅读:
    Android APK反编译具体解释(附图)
    PHP操作数据库PDO
    ios save image to album
    HTTP协议中返回代码302的情况
    ORACLE 创建表空间、用户、授权
    Nginx并发訪问优化
    天将降大任于斯人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为,所以动心忍性,增益其所不能
    TIMESTEN安装配置指南-中文版
    网络直播电视之M3U8解析篇 (下)
    Android Popupwindow 拖动
  • 原文地址:https://www.cnblogs.com/111qqz/p/4534631.html
Copyright © 2011-2022 走看看