zoukankan      html  css  js  c++  java
  • 算法竞赛入门经典程序3-6

    //

    //  excercise.cpp

    //  rumen

    //

    //  Created by Bowie Hsu  on 14/11/19.

    //  Copyright (c) 2014 Bowie Hsu . All rights reserved.

    //

     

    #include "excercise.h"

    #include <iostream>

    #include "stdio.h"

    #include "ctype.h"

    using namespace std;

     

    int main()

    {

     //输入字符串

        char a[20]="ok Madam,i'm adam,i";

        char b[20];

        int p[20];

        int m=0;

        int max=0;

        int str=0,en=0;

        //cin.getline(a,10);

        //判断回文,剔除标点,并将所有的字母转变成大写

        int length=sizeof(a);

        for(int i=0;i<length-1;i++)

        {

         if(isalpha(a[i]))

         {p[m]=i;

             //记录下改变后的字符在原数组中的位置

             b[m++]=toupper(a[i]);

         }

         }

        //判断字符串是否为回文

        for (int i=0; i<length; i++)

            for(int j=i;j<length;j++)

            {

                //判断回 并返回标志

                int ok=1;

                for(int k=i;k<=j;k++)

                if(b[k]!=b[j+i-k])

                 ok=0;

                if(ok && j-i+1>max)

                {max=j-i+1;

                str=p[i];

                en=p[i+max-1];

                }

            }

        cout<<en<<endl;

        for(int i=str;i<en+1;i++)

        {

            printf("%c",a[i]);

        }

        

        

        return 0;

        

    }

     

    //效率存在问题,原书中用的时中间法

  • 相关阅读:
    【pytest学习10】fixture参数化,fixture(params=data)装饰器的data是函数返回值yield request.param ,将带到下面调用为参数的函数中
    Pipfile 文件转换利器——pipfile-freeze
    npm的lock
    调试wmi连接主机进行监控
    RPC电源监控总结
    HTTP协议三次握手过程
    linux常用命令集
    Gym
    Gym
    实验2.2
  • 原文地址:https://www.cnblogs.com/bowiehsu/p/4109162.html
Copyright © 2011-2022 走看看