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. 小程序 wx.getRecorderManager 录音 to 语音识别

    微信扫小程序码看调用效果(自然语言理解小助手) 欢迎转载,请保留原文链接:http://www.happycxz.com/m/?p=125 这次主要是把我的api更新了一下,支持微信小程序新的录音接口 ...

  2. app.config 配置多项 配置集合 自定义配置

    C#程序的配置文件,使用的最多的是appSettings 下的<add key="Interval" value="30"/>,这种配置单项的很方便 ...

  3. [转载] Redis快速入门

    转载自http://www.yiibai.com/redis/redis_quick_guide.html Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序 ...

  4. Python之Threading模块

    Thread 先引入一个例子: >>> from threading import Thread,currentThread,activeCount >>> > ...

  5. 封装一个通过class获取元素的方法--我的JS原生库(1)

    function getByClass(oParent,sClass){ var aEle = oParent.getElementsByTagName('*'); var result = []; ...

  6. Golang源码探索(三) GC的实现原理

    Golang从1.5开始引入了三色GC, 经过多次改进, 当前的1.9版本的GC停顿时间已经可以做到极短. 停顿时间的减少意味着"最大响应时间"的缩短, 这也让go更适合编写网络服 ...

  7. overflow-x: scroll;横向滑动详细讲解

    overflow-x: scroll;横向滑动(移动端使用详解) css3 , ie8以上 <!DOCTYPE html> <html lang="en"> ...

  8. Java提高十七:TreeSet 深入分析

    前一篇我们分析了TreeMap,接下来我们分析TreeSet,比较有意思的地方是,似乎有Map和Set的地方,Set几乎都成了Map的一个马甲.此话怎讲呢?在前面一篇讨论HashMap和HashSet ...

  9. 《java.util.concurrent 包源码阅读》10 线程池系列之AbstractExecutorService

    AbstractExecutorService对ExecutorService的执行任务类型的方法提供了一个默认实现.这些方法包括submit,invokeAny和InvokeAll. 注意的是来自E ...

  10. mysql导入导出命令(Linux+Windows)

    Linux环境: 壹.首先查看mysql的数据存放路径:ps -ef|grep mysql 贰.进入上述查出的mysql数据存放路径:cd  var/lib/mysql   (数据存放路径) 叁.导出 ...