题目:

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.

#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
char str[102];
int num[102];
int cntt(int i,int j){int cnt=0;while(i<j){if(str[i]!=str[j-1]){cnt++;}i++;j--;}return cnt;
}
int main(){while(~scanf("%s",str)){int minn;int len=strlen(str);for(int i=0; i<len/2; i++){num[i]=i+cntt(i,len);}minn=num[0];for(int i=1;i<len/2;i++){minn=min(minn,num[i]);}printf("%d\n",minn);}
}

  我到现在没想通什么原理,但真的好方便啊

转载于:https://www.cnblogs.com/ineedyou/p/8471200.html

寒假训练,2.25,J-Palindrome Names (回文相关推荐

  1. C++palindrome partitioning回文分割算法的实现(附完整源码)

    C++palindrome partitioning回文分割算法的实现 C++palindrome partitioning回文分割算法的实现的完整源码(定义,实现,main函数测试) C++pali ...

  2. 动态规划 53:Maximum Subarray,152:Maximum Subarray,266. Palindrome Permutation 回文全排列...

    题意:寻找子数组的和最大. 思路:设置dp数组来保存到第i位的最大和. 判断第i-1位的正负,若dp[i-1]<0 则 dp[i] = nums[i]; 若 dp[i-1] > 0 则 d ...

  3. CodeForces - 932G Palindrome Partition(回文自动机+Palindrome Series优化dp)

    题目链接:点击查看 题目大意:给出一个长度为偶数的字符串,问将其分割成 k 个子串记为 a[ 1 ] , a[ 2 ] ... a[ k ] ,且满足 a[ i ] == a[ k - i + 1 ] ...

  4. poj3280 Cheapest Palindrome(回文串区间dp)

    https://vjudge.net/problem/POJ-3280 猛刷简单dp第一天第三题. 这个据说是[求字符串通过增减操作变成回文串的最小改动次数]的变体. 首先增减操作的实质是一样的,所以 ...

  5. 336. Palindrome Pairs 回文对

    给定一组唯一的单词, 找出所有不同 的索引对(i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串. 示例 1: 输入: ["abcd",& ...

  6. POJ2402 Palindrome Numbers 回文数

    题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...

  7. 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

    题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...

  8. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  9. 2019牛客暑期多校训练营(第六场)C - Palindrome Mouse (回文树dfs)

    题目链接 题意 一个字符串,求有多少对(S,T)(S,T)(S,T),满足S.TS.TS.T是回文串,S是T的子串S是T的子串S是T的子串 思路 题解还没看懂- 看大佬代码,好多在回文树上dfsdfs ...

  10. HDU - 6599 I Love Palindrome String (回文树+Manacher、回文树+hash)

    题目链接 题意 一个长度为3e5的字符串,求长度为iii的字符串满足字符是回文串而且字符串的前一半也是回文串的个数 思路 回文数求出所有的回文字符串,然后用Manacher或者Hash判断是否符合条件 ...

最新文章

  1. 基于SSM实现公交路线管理系统
  2. Interview:算法岗位面试—10.25早上—上海某电公司算法岗位(偏图像算法,国企)技术面试之比赛历程、项目收获(Pytorch和Tensorflow)、未来方向
  3. NEO从源码分析看网络通信
  4. 内核启动的汇编阶段——head.S文件
  5. Vue入坑——vue-router单页面多路由配置
  6. 风控策略和模型的区别_风控策略概述
  7. Javascript高级程序设计3笔记 - 对象
  8. html文件钓起始标志,关于html页面head标签顺序
  9. Qt4_深入信号和槽
  10. 【Eclipse】Spring Tool Suite插件
  11. 前端后台的爱恨情仇——接口调试
  12. 计时器setInterval()、setTimeout()
  13. [转载]《Linux Kernel Development》读书笔记 - 蔚蓝海岸 - C++博客
  14. 对偶式与反函数_图解数字电路中标准式的对偶式和反函数求解
  15. 计算机电源风扇安装方法,机箱风扇怎么装 电脑机箱风扇电源线接法
  16. 精度、召回率、准确率、F-score
  17. 目标检测中常见指标 AP MAP coco Pascal voc 评价指标说明
  18. sql 数据存在包含关系的查询
  19. 【Linux回炉 目录配置】
  20. 为何明朝宦官当道如此严重?

热门文章

  1. [免费活动通知]RAD Studio XE8 技术研讨会(上海、成都)
  2. java中String的常用方法
  3. CSS实现跨浏览器兼容性的盒阴影效果
  4. 请问用Microsoft的VFW函数库怎样设置摄像头的速度?
  5. Bzoj 2064 分裂 题解
  6. 查看JAVA源码的网站
  7. Linux快捷键-命令行下
  8. Linux无法启动(一)
  9. 手工卸载.Net写的win服务
  10. 调用存储过程时报错:There is no ‘username’@'host’ registered