Codeforces Round #305 (Div. 2) A

Source: Internet
Author: User

Description

While Mike is walking in the subway and all of 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 a 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 is a palindrome string and all tho SE strings had the same length.

He asked him and tell him if he had 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 中文版 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.

Examples input
Saba
2
Output
NO
input
Saddastavvat
2
Output
YES
First of all, the length can not be divisible, of course, not meet the requirements. Then we split the string according to the requirements, and judged if it was a palindrome.
#include <iostream> #include <stdio.h> #include <string.h>using namespace Std;int main () {    string s;    int n;    cin>>s;    cin>>n;    if (S.length ()%n)    {        cout<< "NO" <<endl;    }    else    {        int i,j;        int mid=s.length ()/n;        for (i=0;i<n;i++)        {            string ss=s.substr (I*mid,mid);            for (int j=0;j<=ss.length ()/2;j++)            {                if (ss[j]!=ss[ss.length () -1-j])                {                    cout<< "NO" <<endl;                    return 0;                }            }   cout<<ss<<endl;        }        cout<< "YES" <<endl;    }    return 0;}

  

Codeforces Round #305 (Div. 2) A

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.