功能: 计算两个字符串的最大公共字串的长度,字符不区分大小写
输入:char * pFirstStr //第一个字符串
char * pSecondStr //第二个字符串
输出:无
返回:int。最大公共字串的长度
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include "OJ.h"
/*
功能: 计算两个字符串的最大公共字串的长度,字符不区分大小写
输入:char * pFirstStr //第一个字符串
char * pSecondStr //第二个字符串
输出:无
返回:int。最大公共字串的长度
*/
int getCommonStrLength(char * pFirstStr, char * pSecondStr)
{
int fir_len = 0;
int sec_len = 0;
int icnt = 0;
int jcnt = 0;
int count_max = 0;
int temp_fir = 0;
int temp_sec = 0;
int temp_count = 0;
if(pFirstStr == NULL || pSecondStr == NULL)
return 0;
fir_len = strlen(pFirstStr);
sec_len = strlen(pSecondStr);
for (icnt = 0; icnt < fir_len; icnt++)
{
temp_count = 0;
for (jcnt = 0; jcnt < sec_len; jcnt++)
{
if (tolower(pFirstStr[icnt]) == tolower(pSecondStr[jcnt]))
{
temp_fir = icnt;
temp_sec = jcnt;
while (temp_fir <= fir_len && temp_sec <= sec_len)
{
if (tolower(pFirstStr[temp_fir]) == tolower(pSecondStr[temp_sec]))
{
temp_count++;
temp_fir++;
temp_sec++;
}
else
{
break;
}
}
}
else
{
continue;
}
}
if (count_max < temp_count)
{
count_max = temp_count;
}
}
return count_max;
}