Palindrome Names

Kattis - 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的更多相关文章

  1. Kattis - names Palindrome Names 【字符串】

    题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使 ...

  2. IDI Open 2016 H 字符串模拟题

    H - Palindrome Names 题意:给定一个字符串,每次可以向末尾添加一个字符或者更改一个字符.求使得字符串为回文串(从前往后和从后往前读一样)所花费的最小步数. 题解: 看来需要多思考啊 ...

  3. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  4. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  5. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  6. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  7. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  8. [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 ...

  9. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

随机推荐

  1. System.TypeInitializationException: 'The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.'

    下午在调试的时候报错数据库连接就报错我就很纳闷后面用原来的代码写发现还是报错 System.TypeInitializationException: 'The type initializer for ...

  2. 【学习笔记】CSS优先级规则

    CSS的优先级规则很多地方的说法都是错误的,常见错误说法是inline css>内部样式>外部样式,其实并没有这种规定.真正的CSS优先级确定是通过特性值大小确定的,在特性值大小相同的情况 ...

  3. 利用nodejs读取数据库数据生成树结构的json数据

    在做后台管理界面的时候,几乎少不了的一个结构就是树形结构,用来做菜单导航: 那么,最希望的就是树结构的所有数据都是读取的数据库,而不是直接代码当中写死,那我们就一步一步来看: 一,建表 字段通常包括: ...

  4. arcgis jsapi接口入门系列(6):样式

    symbol: function () { //线样式 //样式详情请看官方文档 let style = { //线颜色,支持多种格式: //CSS color string:例如"dodg ...

  5. bufferedinputStream操作

    import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java ...

  6. awk累加

    {a+=substr($14,1,1)}END{a=(a=="")?0:a;print a}' 对a进行累加,如果最后a=0的话,结果为0,否则为a,最后输出a

  7. vue.js学习总结

    下面使用的命令工具为git bash 使用命令行工具搭建vue.js项目 vue.js官网命令行工具安装 为了提升安装速度,建议将 npm 的注册表源设置为国内的镜像 1.输入命令:npm insta ...

  8. 洛谷 P2935 [USACO09JAN]最好的地方Best Spot

    题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...

  9. aspose.cell 给excel表格设置样式

    方法1: Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式 styleTitle.HorizontalAlignment ...

  10. UVA1665 Islands (并查集)

    补题,逆序考虑每个询问的时间,这样每次就变成出现新岛屿,然后用并查集合并统计.fa = -1表示没出现. 以前写过,但是几乎忘了,而且以前写得好丑的,虽然常数比较小,现在重新写练练手.每个单词后面都要 ...