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. ...
随机推荐
- SVN中如何去除版本控制器
SVN,大家都熟悉,做项目都知道,不知道你有没有遇到每次提交的代码的时候,都会把bin和obj自动生成的文件夹提交SVN服务器上 其实这里都不需要提交,每次生成都提交,可能还会容易冲突,如何不让bin ...
- MongoDB自动递增序列
MongoDB没有像SQL数据库外开箱即用自动递增功能.默认情况下,它采用了12字节的ObjectId为_id字段作为主键来唯一地标识文档.然而,可能存在的情况,我们可能希望_id字段有一些其它的自动 ...
- 简述UML类图
注:本文摘自刘伟老师的博客http://blog.csdn.net/lovelion/article/details/7838679,如有侵权,请联系本人! 1.类的UML图示 在UML中,类使用包含 ...
- 兼容IE的滚动条自定义样式
废话不多说,直接上: IE专属的滚动条样式定义,只能设置各种原始结构的颜色,宽高结构等其他样式无法修改: div{ scrollbar-arrow-color: red; /*三角箭头的颜色*/ sc ...
- Azure School女神相邀,把每分钟都过的更充实
也许你不姓「牛」,但是你技术牛啊 所以,请容我叫你一声「牛郎」 (讲真,只是因为你技术牛,不是其他啥原因哈) 平时忙到昏天黑地,一心一意为技术的你 注意看一下日历,因为: !!!七夕节(8月28日)到 ...
- 在idea下创建maven
之前一直用eclipse,现在要用idea写一个安装过程玩玩 一:New Project 二:选择maven,在project SDK上选择你安装的jdk,默认安装在c:/Program Files ...
- myna代码
https://github.com/TalkingData/Myna/tree/master/Dataset https://github.com/TalkingData/Myna
- 各种分布(distribution)
正态分布(Normal distribution),又名高斯分布(Gaussian distribution).若随机变量X服从一个数学期望为μ.方差为σ^2(标准差为σ)的正态分布,记为N(μ,σ^ ...
- hibernate4+spring3+struts2搭建框架实例
1.所需要的JAR包 2.web.xml配置文件,这个和平时的配置是一样的 <?xml version="1.0" encoding="UTF-8"?&g ...
- What is the difference between try/except and assert?
assert only check if a condition is true or not and throw an exception. A try/except block can run a ...