//2013-11-26 22:10#include <stdio.h>#include <string.h>//转化成小写void mytolower(char* strSrc){ while ( *strSrc != '\0') { if ( *strSrc >= 'A' && *strSrc <= 'Z') { *strSrc = *strSrc +32; } strSrc ++; }}//int GetCurCommonStrLength(char* strFirst,char* strSecond){ int nLength = 0; while ( *strFirst == *strSecond) { nLength++; strFirst ++; strSecond++; } return nLength;}//求两个字符串的最大公共字符串的长度,不考虑字符串是否大小写//比如“abcdefghijk”和“bcaabcdedd”返回5int GetCommonStrLength(char* pStrFirst,char* pStrSecond){ if ( NULL == pStrFirst || NULL == pStrSecond) { return 0; } if ( pStrFirst == "" || pStrSecond == "") { return 0; } char strFirsttemp[512] = {0}; char strSecondtemp[512] = {0}; strcpy(strFirsttemp,pStrFirst); strcpy(strSecondtemp,pStrSecond); mytolower(strFirsttemp); mytolower(strSecondtemp); char* strFirst = strFirsttemp; char* strSecond = strSecondtemp; int nCommonLength = 0; while ( *strFirst != '\0') { while ( *strSecond != '\0') { if ( *strFirst == *strSecond) { int nTempCommon = GetCurCommonStrLength(strFirst,strSecond); if ( nTempCommon > nCommonLength) { nCommonLength = nTempCommon; } } strSecond++; } strSecond = strSecondtemp; strFirst++; } return nCommonLength;}int main(){ char* str1 = "abcdefghijk"; char* str2= "bcaabcdedd"; char* str3 = "xxp520jh"; char* str4 = "jh520xp"; int n = GetCommonStrLength(str3,str4); return 0;}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow