Palindrome Names
Palindrome Names
Anna and Bob are having a baby. They both enjoy the advantage of having palindrome names, meaning that their names are spelled the same way forwards and backwards. Wanting to be good parents, they decide to give their child a palindrome name too. The only problem is that they aren’t sure if the one they picked is a palindrome. If it turns out it isn’t a palindrome, they want to change it to a palindrome using as few changes as possible. The allowed changes are:
Change one letter of the name.
Add a letter to the end of the name.
Help Bob and Anna find out how many changes they need to make to the name to make it a palindrome.
Input
Input is the name they have chosen.
Output
Output the number of changes they need to make.
Limits
The length of the name is at least 11 and at most 100100 characters.
The name consists of only lowercase letters a–z.
Sample Input 1 | Sample Output 1 |
---|---|
kaia |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
abcdefgded |
4 |
可以有修改,往最后添字符的骚操作,所以直接暴力贪心就好了
#include<bits/stdc++.h>
using namespace std;
string s;
int main() {
int ans=<<;
cin>>s;
for(int i=;s[i];i++){
int cnt=i,beg=i,ed=s.size()-;
while(beg<=ed){
if(s[beg]!=s[ed])
cnt++;
beg++;
ed--;
}
ans=min(ans,cnt);
}
cout<<ans<<endl;
return ;
}
Palindrome Names的更多相关文章
- Kattis - names Palindrome Names 【字符串】
题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使 ...
- IDI Open 2016 H 字符串模拟题
H - Palindrome Names 题意:给定一个字符串,每次可以向末尾添加一个字符或者更改一个字符.求使得字符串为回文串(从前往后和从后往前读一样)所花费的最小步数. 题解: 看来需要多思考啊 ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Palindrome Linked List 回文链表
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
随机推荐
- VS局域网断点调试设置
1.电脑文档文件夹下\IISExpress\config文件内找到applicationhost.config文件编辑 找到<sites>节点 找到你要编辑的site节点 在<bin ...
- 一步步实现自己的ORM(四)
通过前3章文章,大致对ORM有一定的了解,但也存在效率低下(大量用了反射)和重复代码,今天我们要对ORM进行优化. 具体流程如下: 我们优化的第一个就是减少反射调用,我的思路是定义一个Mapping, ...
- CentOS7.2+MySQL5.7_ yum源方式_ 安装配置教程
1)访问mysql官方网站 #访问网站 https://dev.mysql.com/downloads/file/?id=470281 2)下载安装包到linux #进入文件存放路径 cd /usr/ ...
- Android学习总结(十六) ———— MediaPlayer播放音频与视频
一.基本概念 本文主要介绍的是Android中很重要也最为复杂的媒体播放器(MediaPlayer)部分的架构.Android的MediaPlayer包含了Audio和video的播放功能,在Andr ...
- Perl sendmail
introduction of sendmail example send mail to multi-receiver
- 转载自infoq:MYSQL的集群方案
分布式MySQL集群方案的探索与思考 2016-04-29 张成远 “本文整理自ArchSummit微信大讲堂张成远线上群分享内容 背景 数据库作为一个非常基础的系统,任何一家互联网公司都会 ...
- uva12264 Risk
最小值最大,就二分判断. map[i] = '0'+map[i];这样更方便 每个点拆成i,i’, S连i,cap为a[i],i’连T,cap为1(保证至少剩一个)或mid. i,i’ ,a[i] ...
- 浏览器输入一个url到整个页面显示出来经历了哪些过程?
https://cloud.tencent.com/developer/article/1396399 https://www.cnblogs.com/haonanZhang/p/6362233.ht ...
- 关于img
为img添加属性max-width min-height之类的属性可以对图片溢出部分实行自动裁剪功能 非常方便!!!!!!!!!(仅适用于那些原始图片大于max-width,max-height的图片 ...
- Vue-Quill-Editor 富文本编辑器的使用
步骤如下: 1.下载Vue-Quill-Editor npm install vue-quill-editor --save 2.下载quill(Vue-Quill-Editor需要依赖) npm i ...