longest common str
#include <vector>
#include <iostream>
#include <string>
using namespace std; int longest_common_string(string& str_a, string& str_b) {
int len_a = str_a.length();
int len_b = str_b.length();
if ( == len_a || == len_b) {
return ;
}
int rows = len_a + ;
int cols = len_b + ;
int ** comm_len_array = new int * [rows];
int i = ;
for (i=; i < rows; i++) {
comm_len_array[i] = new int[cols];
} int j = ;
for (i = ; i < rows; i++) {
for (j = ; j < cols; j++) {
comm_len_array[i][j] = ;
}
} int max = INT_MIN;
int end_sub_str_a = -;
int end_sub_str_b = -;
for (i = ; i < rows; i++) {
for (j = ; j < cols; j++) {
if (str_a[i - ] == str_b[j - ]) {
comm_len_array[i][j] = comm_len_array[i - ][j - ] + ;
} else {
comm_len_array[i][j] = ;
} if (comm_len_array[i][j] > max) {
max = comm_len_array[i][j];
end_sub_str_a = i;
end_sub_str_b = j;
}
}
} for (i=; i < rows; i++) {
delete[] comm_len_array[i];
}
delete[] comm_len_array; return max;
} int main() {
string stra = "abcedefg";
string strb = "abcf";
cout << longest_common_string(stra, strb) << endl;
}
longest common str的更多相关文章
- SPOJ LCS2 - Longest Common Substring II
LCS2 - Longest Common Substring II A string is finite sequence of characters over a non-empty finite ...
- 14. Longest Common Prefix
题目: Write a function to find the longest common prefix string amongst an array of strings. Subscribe ...
- 【LeetCode】14. Longest Common Prefix 最长前缀子串
题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子 ...
- 【LeetCode】14 - Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. Solution: cla ...
- hdu 1403 Longest Common Substring(最长公共子字符串)(后缀数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1403 Longest Common Substring Time Limit: 8000/4000 MS (Ja ...
- leetcode【14题】Longest Common Prefix
题目:Longest Common Prefix 内容: Write a function to find the longest common prefix string amongst an ar ...
- Leetcode 14——Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings. 很简单的一个描述,最 ...
- [Swift]LeetCode14. 最长公共前缀 | Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is n ...
- LeetCode专题-Python实现之第14题:Longest Common Prefix
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...
随机推荐
- Javascript 绝对定位和相对定位
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- **【ci框架】精通CodeIgniter框架
http://blog.csdn.net/yanhui_wei/article/details/25803945 一.大纲 1.codeigniter框架的授课内容安排 2.codeigniter框架 ...
- PHP WAMP关闭notice等提示
这是xdebug的的错误报告.在开发环境下,可以考虑将其开启,但是在部署到真实应用环境下应该将其关掉. 找到你的php.ini 在最后几行注释掉所有关于xdebug的东西,重启apache即可!
- JAVA! static什么作用?
是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中任何变量或者代码都是在编译时由系统自动分配内存来存储的,而所谓静态就是指在编译后所分配的内存会一直存在,直到程序退出内存才会释放这个空间,也就是只 ...
- 创业草堂之一:创业的Idea是怎样产生的?
“创业”,在很多人的想象中,就是两个小伙子在车库里.或者在学生寝室里,侃出了一个Idea,然后找到了一个投资人或VC,经过几句话讲解,VC拍手叫绝,10钟内当场拍板,砸下了2000万美金,然后两小伙子 ...
- photoshop:多边形选项
你会制作圆滑的五角星吗? 以五边形为例:
- Spring面向切面编程(AOP,Aspect Oriented Programming)
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- set集合_定长
//set集合的操作 //便利初始化函数 NSSet *set1 = [[NSSet alloc] initWithObjects:@"aa", @&q ...
- HDU 4358 Boring counting 树状数组+思路
研究了整整一天orz……直接上官方题解神思路 #include <cstdio> #include <cstring> #include <cstdlib> #in ...
- 整理了一份招PHP高级工程师的面试题
1. 基本知识点 HTTP协议中几个状态码的含义:1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码 ...