华为OJ中级题-查找两个字符串a,b中的最长公共子串
2015-11-22 13:27
567 查看
查找两个字符串a,b中的最长公共子串。
void hwOJ(){ string a = "abcdefghijklmnop"; string b = "abcsafjklmnopqrstuvw"; int lena = a.length(); int lenb = b.length(); int st1 = 0, st2 = 0,st=0; int count = 0, MAx = 0; string tmp = "", longStr = ""; for (int i = 0; i < lena; ++i){ for(int j = 0; j < lenb; ++j){ st1 = i; st2 = j; while (a[st1] == b[st2]&&st1<lena&&st2<lenb){ ++st1; ++st2; ++count; } if (count > MAx){ MAx = count; st = i; } count = 0; } } string str; for (int i = 0; i < MAx; ++i){ str.push_back(a[i + st]); } cout << str; }
相关文章推荐
- linux 775和777权限有什么区别
- [LeetCode]Jump Game II
- gdb逆向调试
- ubuntu14.04完全卸载mysql
- mac 在 finder 当前 路径下 打开 terminal 的办法
- 架构的那些事2--安卓的奋进
- linux su和sudo命令的区别
- 数据类型输出
- 指令
- 【BZOJ】1532: [POI2005]Kos-Dicing
- web前端图表js选择-推荐highcharts
- [LeetCode]Longest Substring Without Repeating Characters
- 一些想法
- JS获取CSS样式(style/getComputedStyle/currentStyle)
- 【BZOJ】1524: [POI2006]Pal
- 进制之间的转换
- 优先级
- input标签placeholder属性IE8及以下版本的兼容性问题
- C++ Runtime Error :STL list "list iterator not incrementable"
- ffmpeg叠加srt字幕