zoukankan      html  css  js  c++  java
  • Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串

     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 kpalindromes 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

     

    HINT

    题意

    给你个字符串,告诉你这个字符串是由k个相同长度的回文串构成的,判断是否正确

    题解:

     数据范围很小,暴力判断就好了

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     string str;
     6     int k,n;
     7     int id;
     8     cin>>str>>k;
     9     /**如果恰没有k个的时候是输出NO 没考虑这个条件一直wa*/
    10     if(str.length()%k != 0) {
    11         cout<<"NO"<<endl;
    12         return 0;
    13     } 
    14     n = str.length()/k;
    15     bool ans = false;
    16     /**分成K组进行判断 如果有一组不满足回文串条件  则确定输出NO*/ 
    17     for(int i = 1; i <= k; i++) {
    18         int bi = (i-1)*n;
    19         int ei =  i*n-1;
    20         while(bi <= ei) {
    21             if(str[bi] != str[ei]) {
    22                 ans = true;
    23                 break;
    24             }
    25             ei--;
    26             bi++;
    27         }
    28         if(ans) break;
    29     }
    30     if(ans) cout<<"NO"<<endl;
    31     else cout<<"YES"<<endl;
    32     return 0;
    33 }
  • 相关阅读:
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    springcloud~feign POST form-url-encoded data
    java~和.net相通的DES-ECB加解密技术
    java的byte和C#的byte的不同之处
    spi~动态监控目录的jar实现热加载
    jboss( WildFly)上运行 springboot程序
    nc
  • 原文地址:https://www.cnblogs.com/jj81/p/8893678.html
Copyright © 2011-2022 走看看