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
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个等长回文串组成的

思路:

水题,暴力

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std; #define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 500005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x) char str[1005];
int len;
int main()
{
int i,j,k;
while(~scanf("%s%d",str,&k))
{
len = strlen(str);
if(len%k)
{
printf("NO\n");
continue;
}
int r = len/k,flag = 0;
for(i = 0; i<len; i+=r)
{
for(j=i; j<i+r; j++)
{
if(str[j]!=str[(i+r)-1-j+i])
{
flag = 1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("NO\n");
else
printf("YES\n");
} return 0;
}

Codeforces548A:Mike and Fax的更多相关文章

  1. 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/pro ...

  2. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  3. A - Mike and Fax

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description While ...

  4. CodeForces 548A Mike and Fax (回文,水题)

    题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...

  5. CodeForces 548

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

  6. C# 事件 解析

    1.什么是事件,事件和委托什么关系? 事件?事件,就是,比如按一个按钮,弹出你好对话框,就是一个事件. 事件和委托? 事件就是委托的一种呀,委托可以理解为回调机制,回调函数. 2. 怎么理解C#事件, ...

  7. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. CF #305(Div.2) D. Mike and Feet(数学推导)

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)

    C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. 关于双11过后MATLAB许可过期问题的解决方案

    在距离双11还有2个月之前,matlab会提示:Your MATLAB license will expire in 50 days --------------------------------- ...

  2. oracle精简客户端安装配置及常见问题

    有关Instant client 安装步骤 1.首先在官网下载两个安装包instant/sqlplus,对相关文件进行解压缩,存放本地路径 官网地址:http://www.oracle.com/tec ...

  3. Dev控件treeList

    之前做过一段时间,当时copy 的别人的代码,这就就把节点给添加了,上次帮同事做也发现了这个问题,当时没有记下来,今天有做,磨了半天,记下来吧. Dev控件treeList 要添加节点第一步是右键添加 ...

  4. JavaScript学习笔记(二)——字符串

    在学习廖雪峰前辈的JavaScript教程中,遇到了一些需要注意的点,因此作为学习笔记列出来,提醒自己注意! 如果大家有需要,欢迎访问前辈的博客https://www.liaoxuefeng.com/ ...

  5. 利用 WSL 在 Windows下打造高效的 Linux 开发环境

    WSL-Windows Subsystem for Linux 介绍 The Windows Subsystem for Linux lets developers run Linux environ ...

  6. JavaScript的兼容

    兼容总结 如果两个都是属性,用逻辑 || 做兼容 如果有一个是方法,用三元做兼容 如果多个属性或方法,封装函数做兼容 获取class属性值的兼容 function getClass (obj){ if ...

  7. select2 取值 遍历 设置默认值

    select2 取值 遍历 设置默认值 本章内容主要介绍Select2 的初始化,获取选中值,设置默认值,三个方法.Select2 美化了单选框,复选框和下拉框,特别是下拉框多选的问题.但同时,Sel ...

  8. laravel MethodNotAllowedHttpException错误一个原因

    前两天在写api的时候,出现一个之前都没有碰到过的问题,如图 可以说提示信息是很不友好了,然后打开错误日志,发现报了一个MethodNotAllowedHttpException这样的错误,这样错误我 ...

  9. Net Core下多种ORM框架特性及性能对比

    在.NET Framework下有许多ORM框架,最著名的无外乎是Entity Framework,它拥有悠久的历史以及便捷的语法,在占有率上一路领先.但随着Dapper的出现,它的地位受到了威胁,本 ...

  10. 【译】10个机器学习的JavaScript示例

    原文地址:10 Machine Learning Examples in JavaScript 在过去的每一年,用于机器学习(Machine Learning)的库在变得越来越快和易用.一直以来Pyt ...