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. 破解MySQL和修改mysql的密码

    /etc/init.d/mysql stop mysqld_safe --user=mysql --skip-grant-tables --skip-networking & mysql -u ...

  2. JavaScript数据格式验证探讨

    1.需求 修改某个文本框数据,要求对修改后的格式做验证(必须是数字). 注:实际需求比上述复杂,为了说明问题,这里特意简化了需求(如:对修改后数据依赖条件的判断,数据入库等). 2.关于NaN的探讨( ...

  3. EJB开发基础——EJB规范

    1.EJB 容器          Enterprise Bean 是在称作 EJB 容器的特殊环境中运行的软件组件.容器容纳和管理 Enterprise Bean 的方式与 Java Web 服务器 ...

  4. POJ 1947 Rebuilding Roads (树形DP)

    题意:给一棵树,在树中删除一些边,使得有一个连通块刚好为p个节点,问最少需要删除多少条边? 思路: 因为任一条边都可能需要被删除,独立出来的具有p个节点的连通块可能在任意一处地方.先从根开始DFS,然 ...

  5. COGS 2688. 鱼的感恩

    ★   输入文件:fool.in   输出文件:fool.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 从前有一个渔夫抓到了一条特别的鱼,放走了. 渔夫再次抓到了这条 ...

  6. Windows Dos命令下查看端口号,杀死端口

    PS:本文以 Redis 默认端口 6379 为例   1,首先查询该端口的 pid,使用命令 [netstat -ano | findstr 端口号]   F:\Program Files\Redi ...

  7. HDU 4348 I - To the moon 可持续化

    队友套的可持续化线段树,徘徊在RE和MLE之间多发过的... 复用结点新的线段树平均要log2N个结点. 其实离线就好,按照时间顺序组织操作然后dfs. #include <iostream&g ...

  8. maven项目jsp无法识别jstl的解决办法

    EL表达式无效是因为maven项目的jsp不识别jstl,只要在web-APP 标签中引入命名空间 xmlns="http://xmlns.jcp.org/xml/ns/javaee&quo ...

  9. C#中Lock关键字的使用

    C# 中的 Lock 语句通过隐式使用 Monitor 来提供同步功能.lock 关键字在块的开始处调用 Enter,而在块的结尾处调用 Exit. 通常,应避免锁定 public 类型,否则实例将超 ...

  10. fckeditor配置详解

    使用配置设置: . FCKConfig.CustomConfigurationsPath = '' ; // 自定义配置文件路径和名称 . FCKConfigFCKConfig.EditorAreaC ...