#ifndef MAX_LENGTHCOMMSUBSTR_H#define MAX_LENGTHCOMMSUBSTR_H#define max(a,b) a>b? a:bint maxLengthComSubSTR(char *a_array,char *b_array,int a_index,int b_index){ if(a_index==0||b_index==0){ return 0; } if(a_array[a_index-1]==b_array[b_index-1]){ return maxLengthComSubSTR(a_array,b_array,a_index-1,b_index-1)+1; }else{ return max(maxLengthComSubSTR(a_array,b_array,a_index-1,b_index),maxLengthComSubSTR(a_array,b_array,a_index,b_index-1)); }}#endif
#ifndef MAX_LENGTHCOMMSUBSTR_H
#define MAX_LENGTHCOMMSUBSTR_H
#define max(a,b) a>b? a:b
int maxLengthComSubSTR(char *a_array,char *b_array,int a_index,int b_index){
if(a_index==0||b_index==0){
return 0;
}
if(a_array[a_index-1]==b_array[b_index-1]){
return maxLengthComSubSTR(a_array,b_array,a_index-1,b_index-1)+1;
}else{
return max(maxLengthComSubSTR(a_array,b_array,a_index-1,b_index),maxLengthComSubSTR(a_array,b_array,a_index,b_index-1));
#endif
int main(){ char *str1="BDCABA"; char *str2="ABCBDAB"; std::cout<<maxLengthComSubSTR(str1,str2,6,7)<<std::endl; }
int main(){
char *str1="BDCABA";
char *str2="ABCBDAB";
std::cout<<maxLengthComSubSTR(str1,str2,6,7)<<std::endl;