功能: 计算两个字符串的最大公共字串的长度,字符不区分大小写

功能: 计算两个字符串的最大公共字串的长度,字符不区分大小写

输入: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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值