博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Palindrome Names
阅读量:5884 次
发布时间:2019-06-19

本文共 1372 字,大约阅读时间需要 4 分钟。

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
using namespace std;string s;int main() { int ans=1<<30; cin>>s; for(int i=0;s[i];i++){ int cnt=i,beg=i,ed=s.size()-1; while(beg<=ed){ if(s[beg]!=s[ed]) cnt++; beg++; ed--; } ans=min(ans,cnt); } cout<
<

 

转载于:https://www.cnblogs.com/BobHuang/p/7203200.html

你可能感兴趣的文章
react-native 制作购物车ShopCart
查看>>
Linux服务器 java生成的图片验证码乱码问题
查看>>
【转】QT中QDataStream中浮点数输出问题
查看>>
AD RMS之Windows 内部数据库迁移到 SQL 服务器
查看>>
记录我第一次在Android开发图像处理算法的经历
查看>>
mongodb3.2配置文件yaml格式 详解
查看>>
git设置默认编辑为vim
查看>>
android api (82) —— InputConnection [输入法]
查看>>
数据库事务的四大特性
查看>>
webshell 提升 for linux
查看>>
Java游戏开发中怎样才能获得更快的FPS?
查看>>
文件搜索工具
查看>>
python3.2列表操作总结
查看>>
4.3. Summary
查看>>
SQL Server本地管理员和sa都无法访问的解决方案
查看>>
RH033(2)
查看>>
mongrel启动问题的解决方案
查看>>
Android:UI控件风格与主题、selector、Theme
查看>>
sqlserver 2000/2005 Ambiguous column error错误解决办法
查看>>
spring aop 配置
查看>>