gym100971
来源:互联网 发布:java怎么反序列化 编辑:程序博客网 时间:2024/05/18 17:01
Mihahim has a string s. He wants to delete exactly one character from it so that the resulting string would be a palindrome. Determine if he can do it, and if he can, what character should be deleted.
The input contains a string s of length(2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.
If the solution exists, output «YES» (without quotes) in the first line. Then in the second line output a single integerx — the number of the character that should be removed froms so that the resulting string would be a palindrome. The characters in the string are numbered from 1. If there are several possible solutions, output any of them.
If the solution doesn't exist, output «NO» (without quotes).
evertree
YES2
emerald
NO
aa
YES2
给你一个串然后问你删除一个字符能不能形成回文串
ac代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char a[1000005];int main(){ while(gets(a)) { int len=strlen(a); int sum=0; int p=0,q=len-1; int k; while(p<=q) { if(a[p]==a[q]) { p++;q--; } else { sum++; int sum1=0,sum2=0; int r=p,t=q-1; while(r<=t) { if(a[r]==a[t]) { r++;t--; } else { sum1++;break; } } r=p+1;t=q; while(r<=t) { if(a[r]==a[t]) { r++;t--; } else { sum2++;break; } } sum+=min(sum1,sum2); if(sum1>sum2) k=p; else k=q; break; } } if(sum==0) { printf("YES\n"); printf("%d\n",len/2+1); } if(sum==1) { printf("YES\n"); printf("%d\n",k+1); } if(sum==2) printf("NO\n"); } return 0;}
- gym100971
- gym100971
- 文章标题 Gym100971 L :Chess Match
- 3步告别忙累压力大没成绩
- 还记得你的第一个“对象”吗?
- mongo 常用语句
- 高通RPM部分简介
- 这是一篇最通熟易懂的Hadoop HDFS实践攻略!
- gym100971
- 树状数组_Rotate HDU2688
- 国外牛人总结的机器学习领域的框架、库以及软件
- Property xx cannot be found in forward class object "XXXX"
- 单linux服务器同时拨多条ADSL和挂多个固定公网ip通过squid实现代理池方案
- 编辑平台图层IP占用后解决办法
- MySQL中文乱码问题
- 2017软考考前准备必看
- iOS 开发中常见Property关键字解读