Algorithmic competition Getting Started classic program 3-6

Source: Internet
Author: User

//

Excercise.cpp

Rumen

//

Created by Bowie Hsu on 14/11/19.

Copyright (c) year Bowie Hsu. All rights reserved.

//

#include "Excercise.h"

#include <iostream>

#include "Stdio.h"

#include "Ctype.h"

Using namespace std;

int Main ()

{

// input string

Char a[]="OK madam,i ' m adam,i";

Char b[];

int p[];

int m=0;

int max=0;

int str=0, en=0;

//cin.getline (a,10);

// judge palindrome, remove punctuation , and turn all letters into uppercase

int length=sizeof(a);

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

{

if(isalpha(A[i]))

{p[m]=i;

// record the position of the changed character in the original array

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

}

}

// determine if the string is a palindrome

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

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

{

// judgment back and return flag

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;

}

Efficiency problems, the time intermediate method used in the original book

Algorithmic competition Getting Started classic program 3-6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.