//
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