[006] largest_common_substring
[Description] Given two different strings, find the largest successive common substring.
e.g. str1[]="qwertyuiopasdfgh"; str2[]="jhdfgqwertyudfxcv";
LCsubstr[]="qwertyu";
[Thought] show the correspondence result of this two strings from the 2-D array of 'record[][]', and find the longest non-zero diagonal elements. To save the auxiliary space, we can use only 1-D array 'record[]' to implement. O(n^2) O(m)
[Implementation] C code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h> char* LCS(char longer[], char shorter[])
{
int longer_len=strlen(longer);
int shorter_len=strlen(shorter);
int record[shorter_len];
int i,j,max_len=,substr_end=,substr_begin; for(i=;i<longer_len;i++)
{
for(j=shorter_len-;j>=;j--)
{
if(longer[i]==shorter[j])
{
if(==i || ==j)
{
record[j]=;
}
else
{
record[j]=record[j-]+;
}
}
else
{
record[j]=;
} if(record[j]>max_len)
{
max_len=record[j];
substr_end=j;
}
}
} substr_begin=substr_end-max_len+; // char substr[max_len];
char* substr=(char*)malloc(max_len);
for(i=;i<max_len;i++)
{
substr[i]=shorter[substr_begin+i];
}
return substr;
} int main()
{
char longer[]="asdfghjklqwertyyuio";
char shorter[]="zxvsdffghwerxv"; printf("The longer str:\n\t%s\n",longer);
printf("The shorter str:\n\t%s\n",shorter);
printf("The lagest common str:\n\t%s\n",LCS(longer,shorter));
return ;
}
[006] largest_common_substring的更多相关文章
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数006, image,影像处理(像素图)
<zw版·Halcon-delphi系列原创教程> Halcon分类函数006, image,影像处理(像素图) 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“* ...
- android 入门 006(sqlite增删改查)
android 入门 006(sqlite增删改查) package cn.rfvip.feb_14_2_sqlite; import android.content.Context; import ...
- php大力力 [006节]初步接触认识phpMyAdmin
phpMyAdmin 2015-08-22 php大力力006. 初步接触认识phpMyAdmin 以下是phpAdmin网络截图: 这是通过MAMP一键安装的. php中MyAdmin的使用-猿代码 ...
- [反汇编练习] 160个CrackMe之006
[反汇编练习] 160个CrackMe之006. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- 2017-2018-1 1623 bug终结者 冲刺006
bug终结者 冲刺006 by 20162328 蔡文琛 今日任务:音频素材添加 又是新的一天,小组项目有了很大的起色,已经可以在手机上试玩了. 添加背景音乐能使我们的游戏锦上添花. 音频资源需求 需 ...
- Python:每日一题006
题目:斐波那契数列. 程序分析:斐波那契数列(Fibonacci sequence),又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.…… 个人思路及代码: # 方 ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
- 6.006 Introduction to Algorithms
课程信息 6.006 Introduction to Algorithms
- 『006』Shell脚本
『003』索引-Linux Shell Script Shel脚本-初步入门 [001]- 点我快速打开文章[<01 什么是 Shell>] [002]- 点我快速打开文章[<02 ...
随机推荐
- 第204天:js---重载和多态
一.根据arguments个数实现重载 js本身不支持重载,所以只能通过其他方式实现,arguments检测传参的个数,然后再执行不同的方式 function add() { var sum = 0 ...
- 【Linux】无法将 Ethernet0 连接到虚拟网络“VMnet8”
Linux安装centos之后,可能会出现ipconfig命令之后没有看到eth0信息,只有lo.log日志包的错为:无法将 Ethernet0 连接到虚拟网络“VMnet8” 解决办法有: 1.在虚 ...
- [AT2557] [arc073_c] Ball Coloring
题目链接 AtCoder:https://arc073.contest.atcoder.jp/tasks/arc073_c 洛谷:https://www.luogu.org/problemnew/sh ...
- 【BZOJ1014】火星人(Splay,哈希)
[BZOJ1014]火星人(Splay,哈希) 题面 BZOJ 题解 要动态维护这个串,一脸的平衡树. 那么用\(Splay\)维护这个哈希值就好了. 每次计算答案的时候二分+Splay计算区间哈希值 ...
- A2W W2A等所需要的文件
1.包含头文件 #include <atlbase.h> #include <atlconv.h> 2.在使用前加上,注意,不是在文件都定义. USES_CONVERSION;
- BZOJ1072 排列perm 【状压dp】
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能 被2整除,其中末位为2的有30种,末位为4的有60种. Inpu ...
- Redis的List链表类型命令
List是一个链表结构,主要功能是push.pop.获取一个范围的所有值等等,操作中key理解为链表的名字.list类型其实就是一个每个子元素都是string类型的双向链表.我们可以通过push.po ...
- linux内核设计与实现一书阅读整理 之第一二章整合
第一章:Linux内核简介 一.Unix和linux Unix是一个强大.健壮和稳定的操作系统. 1.Unix内核特点 十分简洁:仅提供几百个系统调用并且有明确的目的: 在Unix中,大部分东西都被( ...
- Hbase(四) 过滤器查询
引言:过滤器的类型很多,但是可以分为两大类——比较过滤器,专用过滤器过滤器的作用是在服务端判断数据是否满足条件,然后只将满足条件的数据返回给客户端: 一.hbase过滤器的分类 1.比较过滤器 行键过 ...
- Ubuntu配置vncserver
https://help.aliyun.com/knowledge_detail/59330.html 首先,安装桌面环境和vnc4server: sudo apt-get install gnome ...