题意:给定一个字符串,要求判断删除一个字符之后能否形成回文串。
分析:因为要删除一个字符,那么显然对称轴只能有一两种情况。
代码:
#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;
}