hdu 1403 Longest Common Substring(求公共子串长度)
2015-08-14 11:33
363 查看
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
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you have to tell the length of the Longest Common Substring of them.
[align=left]Sample Input[/align]
banana
cianaic
[align=left]Sample Output[/align]
3
[align=left]Author[/align]
Ignatius.L
[align=left]Recommend[/align]
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 100100 struct note{ char *vis; int map; }s[N*2]; char a ,b ; 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; }
相关文章推荐
- ThinkPHP开发框架函数详解:C方法
- hdu 5377 Root 原根+离散对数+扩展欧几里得
- ZigBee帧结构汇总(应用层(APS)、网络层(NWK),MAC层,物理层(PHY))
- [LeetCode] Remove Duplicates from Sorted Array
- JS键盘Enter事件
- Simple Game
- SQL Server数据库
- 深入理解Javascript变量作用域
- ReadString在UNICODE下中文乱码的解决办法(CHS)
- AutoMapper 最佳实践
- 狼厂女汉纸报警优化血泪史(一)
- android 安装目录介绍
- vbaexcel
- hdu5113 Black And White(dfs+剪枝)
- 设计模式之简单工厂模式
- 稀疏矩阵(sparse matrix)
- 数组自定义排序
- 软中断和硬中断(转)
- 稀疏矩阵(sparse matrix)
- win10右键怎么添加管理员授权?