返回两个字符中的最长公共子串
来源:互联网 发布:淘宝网 花种子 编辑:程序博客网 时间:2024/06/05 10:48
1,输入:abncdeixox dixcdeixobxg
输出:cdeixo
代码如下:
#include "stdafx.h"#include<stdio.h>#include<string.h>#include<malloc.h>#define MAXSIZE 100int SearchStr(char * pFirstStr, const char * pSecondStr){int lenS;char*p;lenS=strlen(pSecondStr);if(pSecondStr!=NULL){p=strstr(pFirstStr,pSecondStr);if(p)return lenS;}return 0;}void commonStrLength(char*pFirstStr,char*pSecondStr){int i,j,lenS;int length;int maxLength=0;char*temp;char*p;char*final;temp=(char*)malloc(MAXSIZE*sizeof(char));final=(char*)malloc(MAXSIZE*sizeof(char));lenS=strlen(pSecondStr);for(i=0;i<lenS;i++){p=pSecondStr+i;for(j=1;j<=lenS-i;j++){strncpy(temp,p,j);*(temp+j)='\0';length=SearchStr(pFirstStr,temp);if(length>maxLength){strcpy(final,temp);maxLength=length;}}}//printf("%d\n",maxLength);printf("%s\n",final);//return maxLength;}/*char*strBtob(char*ch){char*p;p=ch;if(ch==NULL)return NULL;while(*p!='\0'){if(*p>='A'&&*p<='Z')*p=(*p)+32;p++;}return ch;}*/void main(){int len;char *firstCh;char *secondCh;firstCh=(char*)malloc(100);secondCh=(char*)malloc(100); scanf("%s %s",firstCh,secondCh);//strlwr(firstCh);//strlwr(secondCh);commonStrLength(firstCh,secondCh);//printf("%d\n",len);}
运行结果:
0 0
- 返回两个字符中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- 求两个字符串中的最长公共子串的长度
- 查找两个字符串a,b中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- 求两个字符串a,b中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- 查找两个字符串a,b中的最长公共子串
- LCS两个字符串最长公共子串
- 两个字符串的最长公共子串
- 求两个字符串最长公共子串
- 两个字符串的最长公共子串
- 两个字符串的最长公共子串
- 两个字符串的最长公共子串
- 两个字符串寻找最长公共子串
- 两个字符串的最长公共子串
- HDU 1022 Train Problem I (STL - 栈的使用)
- Asp.net MVC中Html.Partial, RenderPartial, Action,RenderAction 区别和用法
- codeforces 576b
- ::before和::after伪元素的用法
- Arc Engine 开发第五章学习小结
- 返回两个字符中的最长公共子串
- MPLS 调试笔记(一)
- 如何快速理解一个全新的嵌入式操作系统
- 数字证书 从零了解
- Kafka+Storm+HDFS整合实践
- SecureCRT 连接linux 虚拟机连接问题
- 如何将jpg转换成pdf的转换方法
- UIcolor存储在数组
- 项目总结一:微孵化项目总结