求两个字符串的最大公共子串 ,不区分大小写
2014-08-25 23:38
267 查看
<pre name="code" class="cpp"><pre name="code" class="cpp">#include <iostream> #include <string.h> #include <string> using std::cout; using std::cin; using std::endl; using std::string; int getCommonStrLength(const char * pFirstStr, const char * pSecondStr); int main() { string str[2]; for(int i=0;i<2;++i) { cin>>str[i]; } int max=getCommonStrLength(str[0].c_str(),str[1].c_str()); cout<<max<<endl; return 0; } int getCommonStrLength(const char * pFirstStr, const char * pSecondStr) { int max=0; for(int i=0;i<strlen(pFirstStr);++i) { for(int k=0;k<strlen(pSecondStr);++k) { int j=0; while(tolower(pFirstStr[i+j])==tolower(pSecondStr[k+j])) { ++j; if((i+j)>=strlen(pFirstStr) || (k+j)>=strlen(pSecondStr)) { break; } } if(max<j) max=j; } } return max; }
相关文章推荐
- 计算两个字符串的最大公共字串的长度,字符不区分大小写(要求计算连续最长字串的长度)
- 华为机试:计算两个字符串的最大公共字串的长度,字符不区分大小写
- 题目标题: 计算两个字符串的最大公共字串的长度,字符不区分大小写
- 计算两个字符串的最大公共字符串的长度,字符不区分大小写
- 两个字符串的最大公共子串
- 求两个字符串的公共最大子字符串,如asdfsdkgf,kllsdkabc的最大子串为sdk
- 算法题-两个字符串的最大公共子串
- 两个字符串的最大公共子串
- php获得两个字符串公共最大子串的函数
- 求两个字符串的最大公共子串
- C++实现求两个字符串的最大公共子串
- 【字符串操作】 寻找两个字符串中的 最大公共子串
- java实现字符串匹配问题之求两个字符串的最大公共子串
- 求两个字符串的最大公共子串
- 找出两个字符串中最大的公共子串的简单实现
- 求两个字符串的最大公共子串【培训第三天】
- (Relax 后缀数组1.4)POJ 2774 Long Long Message(求两个字符串公共子串的最大长度)
- 求两个字符串最大公共子串
- 找出两个字符串的最大公共子串
- 求两个字符串的最大公共子串