zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    坑爹的微信支付v3,其实没有那么坑
    Mysql探究之null与not null
    Mysql的空值与NULL的区别
    Java编程思想(第4版) 中文清晰PDF完整版
    URI和URL的区别
    html 文本输入框效果大汇集
    HTTP状态码大全
    Silverlight ModelView中调用UI进程
    appium部分api
    appium元素定位
  • 原文地址:https://www.cnblogs.com/xryz/p/4848032.html
Copyright © 2011-2022 走看看