Codeforces Round #305 (Div. 2) 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 k palindromes of the same length.
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).
The second line contains integer k (1 ≤ k ≤ 1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
saba
2
NO
saddastavvat
2
YES
#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的更多相关文章
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
B. Mike and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...
- Codeforces Round# 305 (Div 1)
[Codeforces 547A] #include <bits/stdc++.h> #define maxn 1000010 using namespace std; typedef l ...
- 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 ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
B. Mike and Feet Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
A. Mike and Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...
- 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)
题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...
随机推荐
- 关于fragment生命周期的两张图片
图1,fragment的生命周期,图2,fragment生命周期对应activity的生命周期
- [转]MySQL5.6.22 安装
原文路径 http://jifeng3321.iteye.com/blog/2181517?utm_source=tuicool 由于一直做银行项目,所以一直在用oracle和db2,但最近自己想 ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-005插入排序的改进版
package algorithms.elementary21; import algorithms.util.StdIn; import algorithms.util.StdOut; /***** ...
- p3634 [APIO2012]守卫
传送门 分析 1.先预处理出不被0覆盖的点,然后对每个点处理出在它左边离他最近的点和在他右边理他最近的点. 2.对于每个至少存在一个忍者的区间,先将它左右边界处理为不被0所覆盖.排序后将包含其他区间的 ...
- 如果客户端禁用了cookie,如何实现session
虽然客户端禁用了cookie,那么当访问某一个php文件时,php会先查找php.ini,如果session.use_trans_sid=1/session.use_only_cookie=0,php ...
- javascript字符串 转 驼峰字符
字符串 转 驼峰字符 <script type="text/javascript"> var str = 'peng-hui-datou'; function a( ...
- Mat 类的内存管理
使用 Mat 类,内存管理变得简单,不再像使用 IplImage 那样需要自己申请和释放内存.虽然不了解 Mat 的内存管理机制,也无碍于 Mat 类的使用,但是如果清楚了解 Mat 的内存管理,会更 ...
- DWR原理探秘
DWR原理探秘 DWR(Direct Web Remoting)远程Web命令;是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站.它可 ...
- 第6章 jQuery与Ajax的应用
6.1 Ajax的优势和不足 6.1.1 Ajax的优势 1.不需要插件支持 2.优秀的用户体验 3.提高Web程序的性能 Ajax模式只是通过XMLHttpRequest对象向服务器端提交希望提交的 ...
- C#代码标识符命名规范
总体原则:命名一定要体现其在程序中的作用: Camel命名法:第一个单词的首字母小写,其余每个单词的首字母大写:多用给变量或者字段命名:给字段命名必须以下划线开始: Pascal命名法:每个单词的首字 ...