前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Gym 100971K】Palindromization

【Gym 100971K】Palindromization

作者头像
饶文津
发布2020-06-02 15:51:58
2900
发布2020-06-02 15:51:58
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏

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.

Input

The input contains a string s of length (2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.

Output

If the solution exists, output «YES» (without quotes) in the first line. Then in the second line output a single integer x — the number of the character that should be removed from s 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).

Examples

input

代码语言:javascript
复制
evertree

output

代码语言:javascript
复制
YES
2

input

代码语言:javascript
复制
emerald

output

代码语言:javascript
复制
NO

input

代码语言:javascript
复制
aa

output

代码语言:javascript
复制
YES
2

从左右两边往中间移动,如果相同,l++,r--,如果不同,第一次循环i==0时,则让l++,第二次循环则让r--,最后判断不同的出现了几次。如果dif是0,l>=r代表本身就是回文,则去掉l位置的字符。

代码语言:javascript
复制
#include <cstring>
#include <cstdio>
#define N 100005
char s[N<<1];
int len,l,r,dif,at;
int main() {
    scanf("%s",s);
    len=strlen(s);
    for(int i=0;i<2;i++){
        dif=0;
        l=0,r=len-1;
        while(l<r){
            if(s[l]!=s[r]){
                dif++;
                if(i){
                    at=r;
                    r--;
                }else {
                    at=l;
                    l++;
                }
            }
            if(s[l]==s[r]){
                l++;
                r--;
            }
        }
        if(l>=r&&dif==0)at=l;
        if(dif<2){
            printf("YES\n%d\n",at+1);
            break;
        }
    }
    if(dif>1)puts("NO");
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-08-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档