最长公共子串

来源:互联网 发布:上海大学网络教学 编辑:程序博客网 时间:2024/06/03 13:17

lintcode练习题目

#include "string"#include "stdio.h"#include "iostream"using namespace std;int longestCommonSubstring(string &A, string &B) {        int i,j,max=0;        int dp[400][400]={0};        for(i=1;i<=A.size();i++)        {            for(j=1;j<=B.size();j++)            {               if(A[i-1]==B[j-1])                   dp[i][j]=dp[i-1][j-1]+1;               if(dp[i][j]>max)                   max=dp[i][j];            }        }        return max;}int main(){    string A,B;    cin>>A>>B;    cout<<longestCommonSubstring(A,B)<<endl;    return 0;}
0 0