CodeForces 548A Mike and Fax (回文,水题)
题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长。
析:没什么好说的,每次截取n/k个,判断是不是回文就好。
代码如下:
#include<bits/stdc++.h> using namespace std;
string s; bool judge(string s){
for(int i = 0, j = s.size()-1; i < s.size(); ++i, --j){
if(s[i] != s[j]) return false;
}
return true;
} int main(){
int n;
while(cin >> s){
cin >> n;
bool ok = true;
if(s.size() % n != 0){ puts("NO"); continue; }
int t = s.size() / n;
for(int i = 0; i < s.size(); i += t)
if(!judge(s.substr(i, t))) { ok = false; break; }
if(ok) puts("YES");
else puts("NO");
}
return 0;
}
CodeForces 548A Mike and Fax (回文,水题)的更多相关文章
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- Codeforces Gym100543G Virus synthesis 字符串 回文自动机 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/CF-100543G.html 题目传送门 - CF-Gym100543G 题意 你可以对一个字符串进行以下两种操 ...
- Codeforces Gym100952 C. Palindrome Again !!-回文字符串 (2015 HIAST Collegiate Programming Contest)
C. Palindrome Again !! time limit per test 1 second memory limit per test 64 megabytes input sta ...
- Palindrome Degree(CodeForces 7D)—— hash求回文
学了kmp之后又学了hash来搞字符串.这东西很巧妙,且听娓娓道来. 这题的题意是:一个字符串如果是回文的,那么k值加1,如果前一半的串也是回文,k值再加1,以此类推,算出其k值.打个比方abaaba ...
- codeforces Gym 100187L L. Ministry of Truth 水题
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Palindrome Partitioning (回文子串题)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
随机推荐
- 【转载】Java中如何写一段内存泄露的程序 & ThreadLocal 介绍和使用
可以参考这段文章: link A1:通过以下步骤可以很容易产生内存泄露(程序代码不能访问到某些对象,但是它们仍然保存在内存中): 上文中提到了使用ThreadLocal造成了内存泄露,但是写的不清不楚 ...
- WebClient+Fiddler2完美搭配下载远程页面信息
WebClient可以下载远程页面信息,这个大家应该都知道,核心代码如下: WebClient web = new WebClient(); string url = String.Format(&q ...
- HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...
- jquery 字符串转json
这里考虑的都是服务器返回JSON形式的字符串的形式 代码如下: var data=" { root: [ {name:'1',value:'0'}, {name:'6101',value:' ...
- ASP.NET MVC 传值方法ViewData与ViewBag的区别
一.介绍 在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类 ...
- Android开发之WebService介绍
经常有网友问:“在Android平台如何调用WebService”?经过沟通我发现,甚至有些朋友连什么是WebSerivce都不知道就在问怎么使用,更别说和WebService有关的SOAP.WSDL ...
- WTL汉化版2013.10.15
汉化内容: 2013.10.15 版本:当前可下载Trunk最新版,wtl-code-467-trunk.zip 汉化内容: 1.应用向导的部分汉化,考虑到部分词汇的表述问题,只汉化无影响部分 2.资 ...
- busybox filesystem ts_config: No such file or directory
/******************************************************************** * busybox filesystem ts_config ...
- 【JSP】JSP动态显示时间
function showtime() { var today; var hour; var second; var minute; var year; var month; var date; va ...
- Ajax+PHP简单入门教程
Ajax 由 HTML.JavaScript™ 技术.DHTML 和 DOM 组成,这一杰出的方法可以将笨拙的 Web 界面转化成交互性的 Ajax 应用程序.对于Ajax,最核心的一个对象是XMLH ...