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