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. details和summary可以对内容进行折叠

    使用<details>和<summary>元素 它可以在body的任意地方使用下面有一个小例子 <!DOCTYPE html> <html lang=&quo ...

  2. localstorage本地定时缓存

    在做一个网站时,起初直接就是从服务器获取数据进行交互,没有用一些本地缓存做优化,项目做下来就特别卡,并且对服务器造成了很大的压力,经过请教,查询,找到这样一个定时缓存的例子.html5定时缓存,从数据 ...

  3. IE6中 PNG 背景透明的最佳解决方案

    为什么要使用 PNG 图片? 简 单来说,使用 PNG 格式比起 GIF 来表现色彩更丰富,特别是表现渐变以及背景透明的渐变要比GIF格式出色很多.目前,最新的浏览器基本上都支持PNG格式.唯独有万恶 ...

  4. 网页加速特技之 AMP

    据统计,40%的人会放弃使用加载时间超过3秒的网站.对于加载慢的页面我也是没耐心等待的,同类型网站那么多,为什么不选择加载速度更快体验更好的呢.为了解决网页加载慢的问题,Google联合数十家技术机构 ...

  5. BootStrap的入门和响应式的使用

    在做前端开发中,其实有百分之四十的时间用来布局写样式,百分之三十用来写JS逻辑交互,百分之三十时间用来测试调bug,可以看的到的是,用在布局+样式的时候会比较多, 所以会有很多的前端框架诞生,例如bo ...

  6. 2017EIS CTFwriteup

    EIS2017也就是2017年高校网络信息安全管理 运维挑战赛,全国一百多所高校参赛,侥幸拿了个地区三等奖,事先不知道理论赛占分比,不然就会是二等奖(吐槽),生活没有如果,下次努力吧. 比赛已经结束大 ...

  7. 在SQL Server Express版本中没有代理功能如何自动备份数据库

    因为是免费的且单个数据库可以支持到10GB,对于一般企业完全足够了,也就将就使用了,备份将分为两步: 1.创建备份脚本 2.创建系统的计划任务进行每天的备份 详细做法如下: 1.创建备份脚本 打开SS ...

  8. [最短路]P1078 文化之旅

    题目描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一 种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不 同的国家可能有相同的文化.不同 ...

  9. 晓莲说-何不原创:java 实现二维数组冒泡排序

    新手从业路-为自己回顾知识的同时,也希望和大家分享经验: 话不多说,上代码 public class 冒泡排序 { /**     * @param admin     * @2017.12.4   ...

  10. 【原创】用python写的一个监测本地进程CPU占用的程序

    #coding=utf-8import psutilimport sysimport timetry:#输入需要监测的进程PID PID = raw_input('ProcessPID: ') def ...