IX Samara Regional Intercollegiate Programming Contest K. Palindromization

链接:http://www.codeforces.com/gym/100971/problem/K

题意:给定一个字符串,要求判断删除一个字符之后能否形成回文串。

分析:因为要删除一个字符,那么显然对称轴只能有一两种情况。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=200010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=998244353;
const int INF=1000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
char s[N];
int main()
{
    int i,l,r,w,bo=0,len,ans;
    scanf("%s", s);
    len=strlen(s);
    for (i=len;i;i--) s[i]=s[i-1];
    if (len&1) l=len/2,r=len/2+1;
    else l=len/2-1;r=len/2+1;
    while (l&&s[l]==s[r]) l--,r++;
    if (l==0) bo=1,ans=len;
    else {
        w=r;r++;
        while (l&&s[l]==s[r]) l--,r++;
        if (l==0) {
            bo=1;ans=w;
        }
    }
    if (len&1) l=len/2+1,r=len/2+2;
    else l=len/2,r=len/2+2;
    while (r<=len&&s[l]==s[r]) l--,r++;
    if (r==len+1) bo=1,ans=1;
    else {
        w=l;l--;
        while (r<=len&&s[l]==s[r]) l--,r++;
        if (r==len+1) { bo=1;ans=w; }
    }
    if (bo) printf("YES\n%d\n", ans);
    else printf("NO\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值