• csu 1328 近似回文词


    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    int main()
    {
        int i,k,j,st,maxx,cnt,p[1024],tot,cas=0,x,m,y,xx,yy;
        char s[1024],ss[1024];
        while(~scanf("%d",&k))
        {
            getchar();
            gets(s);
            memset(p,0,sizeof(p));
            memset(ss,0,sizeof(ss));
            int len=strlen(s);
            m=0,maxx=0;
            x=y=1;
            for(i=0;i<len;i++)
            {
    
                if(s[i]>='A'&&s[i]<='Z')
                {
                    p[m]=i+1;
                    ss[m++]=s[i]-'A'+'a';
                }
                else if(s[i]>='a'&&s[i]<='z')
                {
                    p[m]=i+1;
                    ss[m++]=s[i];
                }
            }
    
            for(i=0;i<len;i++)
            {
                for(j=0,tot=0;i-j>=0&&i+j<m;j++)
                {
                    if(ss[i-j]!=ss[i+j])
                        tot++;
                    if(tot>k) break;
                    xx=p[i-j];
                    yy=p[i+j];
                    if(yy-xx>y-x)
                    {
                        x=p[i-j];
                        y=p[i+j];
                    }
                }
    
                for(j=0,tot=0;i-j>=0&&i+j+1<m;j++)
                {
                    if(ss[i-j]!=ss[i+j+1]) tot++;
                    if(tot>k) break;
                    xx=p[i-j];
                    yy=p[i+j+1];
                    if(yy-xx>y-x)
                    {
                        x=p[i-j];
                        y=p[i+j+1];
                    }
                }
    
            }
            //for(i=x;i<=y;i++) printf("%c",s[i]);
            //printf("
    ");
            //if(x==0) x=1;
            printf("Case %d: %d %d
    ",++cas,y-x+1,x);
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    redis>lua脚本
    redis百万级数据存取
    spring之自定义注解
    spring>aop
    git的回退和撤销操作
    vue2.0 v-tap简洁(漏)版 (只解决300ms问题)
    JSONP原理小记
    前端模块加载规范AMD与CMD小记
    html状态码
    使用vue-cli开发时跨域问题
  • 原文地址:https://www.cnblogs.com/xryz/p/4848032.html
Copyright © 2020-2023  润新知