Go: ///
// File:  0528.go
// Author: ymiyamoto
//
// Created on Thu Mar 22 01:52:09 2018
//
package main

import (
	"bufio"
	"fmt"
	"os"
)

var S, T string

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for {
		scanner.Scan()
		S = scanner.Text()
		if len(S) == 0 {
			return
		}

		scanner.Scan()
		T = scanner.Text()

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

		dp[0][0] = 0
		for i := range S {
			for j := range T {
				if S[i] == T[j] {
					dp[i+1][j+1] = max(dp[i+1][j], max(dp[i][j+1], dp[i][j]+1))
				} else {
					dp[i+1][j+1] = 0
				}
			}
		}
		var m int
		for i := range dp {
			for j := range dp[i] {
				m = max(m, dp[i][j])
			}
		}
		fmt.Println(m)
	}
}

C++: #include<iostream>
#include<string>

using namespace std;

int main()
{
	string str,str2;
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		int ans=0;
		if(str.size()>str2.size())
		{
			string a;
			a=str2;
			str2=str;
			str=a;
		}
		
		for(int i=0;i<str.size();i++)
		{
			for(int j=ans+1;i+j<=str.size();j++)
			{
				string se;
				se=str.substr(i,j);
				if(str2.find(se)!=-1)
				{
					if(ans<se.size())
						ans=se.size();
				}
				else
				{
					break ;
				}
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char s[4001], t[4001];
int dp[4001][4001];

int main() 
{
	while (scanf("%s %s", s, t) != EOF){
		memset(dp, 0, sizeof(dp));
		int n = strlen(s);
		int m = strlen(t);
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				if (s[i - 1] == t[j - 1]){
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
			}
		}
		
		int maxi = 0;
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				maxi = max(maxi, dp[i][j]);
			}
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    string s1, s2;
    while ( cin >> s1 >> s2 ) {
        if ( s1.size() > s2.size() ) {
            swap( s1, s2 );
        }
        int lcss = 0;
        int L1 = s1.size();
        int L2 = s2.size();
        for ( int i = -L1-L1; i < L1 + L1; ++ i ) {
            int css = 0;
            for ( int j = 0; j < L2; ++ j ) {
                if ( i + j < 0 || i + j >= L1 ) continue;
                if ( s1[i + j] == s2[j] ) {
                    css ++;
                    lcss = max( lcss, css );
                } else {
                    css = 0;
                }
            }
        }
        cout << lcss << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string a,b;
    while(cin>>a>>b){
        int ans = 0;
        reverse(a.begin(),a.end());
        for(int i=0;i<b.size();++i){
            a+="0";
        }
        reverse(a.begin(),a.end());
        for(int i=0;i<a.size();++i){
            int count=0;
            for(int j=0;j+i<a.size()&&j<b.size();++j){
                if(a[i+j]==b[j]){
                    ++count;
                }else{
                    ans=max(ans,count);
                    count=0;
                }
            }
            ans=max(ans,count);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
short dp[4001][4001];
using namespace std;
int main(){
  string s,str;
  short ans = 0;
  while(cin >> s >> str){
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[j]){
          dp[i+1][j+1] = dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstring>
#include<string>

using namespace std;
int len[4001][4001];

int main(void){
	int a,b;
	while(1){
		memset(len,0,sizeof(len));
		string str;
		string str2;
		int ans=0;
		cin >> str;
		if(str=="EOF")break;
		cin >> str2;
		for(a=0;a<str.size();a++){
			int res=0;
			string tmp= str.substr(a, str.length()-a);
			for(b=0;b<min(tmp.size(),str2.size());b++){
				if(tmp[b]==str2[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str2.size())-1==b)ans=max(res,ans);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
short dp[4001][4001];
using namespace std;
int main(){
  string s,str;
  int ans = 0;
  while(cin >> s >> str){
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[j]){
          dp[i+1][j+1] = dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
}

C++: 
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

int dp[4001][4001];

int main()
{
  string a, b;
  int ans = 0;
  while(cin >> a >> b)
  {
    for(int i = 0; i < a.length(); i++)
    {
      for(int j = 0; j < b.length(); j++)
      {
        if(a[i + 1] == b[j + 1])
          ans = max(dp[i + 1][j + 1] = dp[i][j] + 1, ans);
        else
          dp[i + 1][j + 1] = 0;
      }
    }
    
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dp[4005][4005];
int main(){
	string s1, s2;
	cin >> s1 >> s2;
	s1 = " " + s1;s2 = " " + s2;
	fill((int*)dp, (int*)(dp+4005), 0);
	int ans = 0;
	for(int i = 1;i <= s1.size();i++){
		for(int j = 1;j <= s2.size();j++){
			if(s1[i] == s2[j])dp[i][j] = dp[i-1][j-1]+1;
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}