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>
#define N 4001
using namespace std;

int main(){
  string data;
  string indata;
  int n[2][N];
  while(cin >> data){
    cin >> indata;

    int size1, size2;
    size1=data.size();
    size2=indata.size();

    n[1][0]=0;
    for(int i=0;i<=size1;i++){
      n[0][i]=0;
    }
    int now;
    for(int i=1;i<=size2;i++){
      now=i%2;
      for(int j=1;j<=size1;j++){
        if(data[j-1]==indata[i-1]){
	  if(now){
	    n[1][j]=n[0][j-1]+1;
	  }
	  else{
	    n[0][j]=n[1][j-1]+1;
	  }
        }
        else{
          n[now][j]=n[now][j-1];
        }
      }
    }
    if(n[0][size1]>=n[1][size1]){
      printf("%d\n", n[0][size1]);
    }
    else{
      printf("%d\n", n[1][size1]);
    }
  }
  return 0;
}

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

using namespace std;

string A,B;
int lenA,lenB;

short dp[4096][4096];

int main(){
  while(cin >> A >> B){
    lenA = A.size(), lenB = B.size();
    memset(dp, 0, sizeof(dp));
    for(int i=0;i<lenA;i++){
      for(int j=0;j<lenB;j++){
	if(A[i]==B[j]) dp[i+1][j+1] = dp[i][j]+1;
      }
    }
    short res = 0;
    for(int i=0;i<=lenA;i++) for(int j=0;j<=lenB;j++) res = max(res, dp[i][j]);
    cout << res << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int ans=0;
int cal(string s1,string s2,int s,int p)
{
	int cnt=0;
	for(int i=p;i<s2.size();i++)
	{
		if(s1[i+s]==s2[i])cnt++;
		else break;
	}
	return cnt;
}
int main()
{
	string s1,s2;
	while(cin >> s1 >> s2)
	{
		ans=0;
		for(int i=0;i<s1.size();i++)
		{
			for(int j=0;j<s1.size()-i;j++)
			{
				if(s2[j]==s1[j+i])
				{
					ans=max(ans,cal(s1,s2,i,j));
				}
			}
		}
		cout << ans << endl;
		s1.clear();
		s2.clear();
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int main() {
	string a,b;
	cin>>a>>b;
	int sum=0;
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			if(a[i]==b[j]){
				int sum2=0;
				int i2=i,j2=j;
				while(i2<a.length()&&j2<b.length()&&a[i2]==b[j2]){
					sum2++;
					i2++;
					j2++;
				}
				sum=max(sum,sum2);
			}
		}
	}
	cout<<sum<<endl;
}

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

using namespace std;

char s1[4001], s2[4001];

int main(){
	while(true){
		memset(s1, 0, sizeof(char) * 4001);
		memset(s2, 0, sizeof(char) * 4001);
		if(!(cin >> s1 >> s2)){ break; }
		int l1 = strlen(s1), l2 = strlen(s2), answer = 0;
		for(int ofs = 1 - l2; ofs < l1; ofs++){
			int last = min(l1, ofs + l2), cur = 0;
			for(int i = max(0, ofs); i < last; i++){
				if(s1[i] != s2[i - ofs]){
					answer = max(answer, cur);
					cur = 0;
				}else{
					cur++;
				}
			}
			answer = max(answer, cur);
		}
		cout << answer << endl;
	}
	return 0;
}