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 ;
}

最新文章

  1. 任意多边形切割/裁剪(附C#代码实现)
  2. jQuery 顺便学习下CSS选择器 奇偶匹配nth-child(even)
  3. 龙威零式_团队项目例会记录_18 (Beta架构讨论)
  4. Java里this的作用和用法
  5. Angular:手动脏检查/$apply/$digest和监控对象/$watch
  6. typeof instanceof
  7. DW(二):SqlServer PDW
  8. SQL Server 2012 Enterprise Core Edition和SQL Server 2012 Enterprise Edition的区别
  9. 跨平台传输中使用base64来保证非ascii码字符串的完整性
  10. parentViewController
  11. javascript 检测密码强度
  12. php管理关系工具Composer 之安装与下载
  13. amd和cmd区别
  14. 开发板访问linux方法
  15. 将html5项目部署到tomcat上,并实现安卓手机访问
  16. 请求转发(forward)和重定向(redirect)的区别
  17. MyBatis探究-----动态SQL详解
  18. SQL Server跨服务器查询
  19. pthread_cleanup_push()/pthread_cleanup_pop()的详解
  20. Ansible 实战:一键安装 LNMP

热门文章

  1. Mongo学习
  2. vagrant教程
  3. linux增加系统监视器的快捷键
  4. body和普通div背景图宽高百分比的区别
  5. IO多路复用机制(转)
  6. IOS之网络状态设和NSUserDefaults的synchronize
  7. UVA 10572 Black &amp; White (状压DP)
  8. COGS 1144. [尼伯龙根之歌] 精灵魔法
  9. COGS 1786. 韩信点兵
  10. 如何让Sublime Text编辑器支持新的ABAP关键字