hdu 1403 Longest Common Substring(求公共子串长度)
来源:互联网 发布:淘宝客推广位是什么 编辑:程序博客网 时间:2024/04/28 02:40
Longest Common Substring
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5011 Accepted Submission(s): 1745
Problem Description
Given two strings, you have to tell the length of the Longest Common Substring of them.
For example:
str1 = banana
str2 = cianaic
So the Longest Common Substring is "ana", and the length is 3.
For example:
str1 = banana
str2 = cianaic
So the Longest Common Substring is "ana", and the length is 3.
Input
The input contains several test cases. Each test case contains two strings, each string will have at most 100000 characters. All the characters are in lower-case.
Process to the end of file.
Process to the end of file.
Output
For each test case, you have to tell the length of the Longest Common Substring of them.
Sample Input
bananacianaic
Sample Output
3
Author
Ignatius.L
Recommend
We have carefully selected several similar problems for you: 1404 1418 1422 1409 1427
#include<stdio.h>#include<algorithm>#include<stdlib.h>#include<iostream>#include<string.h>using namespace std;#define N 100100struct note{char *vis;int map;}s[N*2];char a[N],b[N];int cmp(const void *a,const void *b){return strcmp(((note *)a)->vis,((note *)b)->vis);}int fun(char *a,char *b){int len=0;while(*a++==*b++)len++;return len;} int main(){int str1,str2,i;while(~scanf("%s%s",&a,&b)){str1=strlen(a);str2=strlen(b);for(i=0;i<str1;i++){s[i].vis=a+i;s[i].map=1;}for(i=0;i<str2;i++){s[i+str1].vis=b+i;s[i+str1].map=-1;}int max,tem;max=0;qsort(s,str1+str2,sizeof(note),cmp);for(i=0;i<str1+str2-1;i++){if(s[i].map!=s[i+1].map&&(tem=fun(s[i].vis,s[i+1].vis))>max)max=tem;}printf("%d\n",max);}return 0;}
0 0
- hdu 1403 Longest Common Substring(求公共子串长度)
- hdu 1403 Longest Common Substring 后缀数组求最长公共子串
- hdu 1403 Longest Common Substring 后缀数组求最长公共子串
- HDU 1403 & POJ 2774 Longest Common Substring (后缀数组啊 求最长公共子串 模板题)
- 最长公共子串 Longest common subString
- 最长公共子串(Longest-Common-Substring)
- 最长公共子串 Longest Common SubString
- HDU 1403 Longest Common Substring(后缀数组 最长公共子串)
- POJ 2774 Long Long Message+Hdu 1403 Longest Common Substring (后缀数组 最长公共子串)
- SPOJ 1812 Longest Common Substring II 后缀自动机求多字符串最长公共子串
- hdu1403---Longest Common Substring(后缀数组求2个字符串的最长公共子串)
- SPOJ 题目1811 LCS - Longest Common Substring(后缀自动机求最长公共子串)
- 最长公共子串(Longest-Common-Substring,LCS)
- 最长公共子串(Longest-Common-Substring,LCS)
- 最长公共子串(Longest Common Substring)
- 最长公共子串(Longest Common Substring, LCS)
- 最长公共子串 Longest-Common-Substring(LCS)
- [Lintcode]Longest Common Substring最长公共子串
- nodejs,async同步执行方法
- 量化投资:数据挖掘技术与实践(MATLAB版)——互动出版网
- poj 3080 Blue Jeans
- cocos2d-x-3.4 无法打开包含文件extensions/ExtensionExport.h
- ZigBee帧结构汇总(应用层(APS)、网络层(NWK),MAC层,物理层(PHY))
- hdu 1403 Longest Common Substring(求公共子串长度)
- iOS应用如何跳转到设置界面
- 常见第三方库及其功能简介
- div+css3做的小图标
- Android BaseAdapter 更新数据 notifyDataSetInvalidated() notifyDataSetChanged()
- hive的数据类型和数据模型
- Android中SMS的接收处理
- 决策树,随机森林,boost小结
- java动态缓存成长小纪(三)——缓存大小估算