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++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-8;

short dp[4001][4001];

int main(){
	string str1;
	while(cin>> str1){
		memset(dp,0,sizeof(dp));

		string str2;
		cin >> str2;

		for(int i=0;i<str1.size();i++){
			for(int j=0;j<str2.size();j++){
				if(str1[i] == str2[j]){
					dp[i+1][j+1] = dp[i][j]+1;
				}
				else{
					dp[i+1][j+1] = 0;
				}
			}
		}

		short res=0;
		for(int i=0;i<=str1.size();i++){
			for(int j=0;j<=str2.size();j++){
				res = max(res,dp[i][j]);
			}
		}

		printf("%d\n",res);
	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

int dp[4001][4001];
int main()
{
	string s;
	string t;
	while (cin >> s && s != "")
	{
		memset(dp, 0, sizeof(dp));
		cin >> t;
		int ans = 0;
		for (int i = 0; i < s.size(); i++)
		{
			for (int j = 0; j < t.size(); j++)
			{
				if (s[i] == t[j])
				{
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = max(dp[i + 1][j + 1], ans);
				}
				else
				{
					dp[i + 1][j + 1] = 0;
				}
			}
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
	string s, t;
	int n, m;
	while(getline(cin, s)){
		getline(cin, t);
		n = s.size();
		m = t.size();

		string res = "";
		for(int i = -n + 1; i < m; i++){
			string c = "";
			int ind = max(i, 0);
			while(ind - i< n && ind < m){
				c = "";
				while(ind - i < n && ind < m && s[ind-i] == t[ind]){
					c += s[ind-i];
					ind++;
				}
				ind++;
				if(c.size() >= res.size()) res = c;
			}
		}
		cout << res.size() << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
    string a,b;
    while(cin>>a>>b){
	int MAX=0;
	for(int c=0;c<a.length();c++){
	    for(int d=0;d<b.length();d++){
		int e=0;
		for(;c+e<a.length()&&d+e<b.length();e++){
		    if(a[c+e]!=b[d+e])break;
		    }
		    MAX=max(e,MAX);
		}
	    }
	    cout<<MAX<<endl;
	}
    }

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short dp[4001][4001]={};
char str1[4005],str2[4005];
int ans=0;
int main(){while(scanf("%s%s",str1,str2)!=-1){
  for(int i=0;i<strlen(str1);i++){
    for(int j=0;j<strlen(str2);j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,1);}
         else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}}printf("%d\n",ans); }return 0;}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S, T; int v, _max;
int main() {
	while (v < 10) {
		v++;
		_max = 0;
		cin >> S >> T;
		for (int i = 1; i <= min(T.size(),S.size()); i++) {
			for (int j = 0; j <= S.size() - i; j++) {
				for (int k = 0; k <= T.size() - i; k++) {
					if (S.substr(j, i) == T.substr(k, i)) {
						_max = i;
					}
				}
			}
		}
		cout << _max << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[4001][4001]={};
char str1[4005],str2[4005];
int ans=0;
int main(){while(
  scanf("%s%s",str1,str2)!=-1){
  for(int i=0;i<strlen(str1);i++){
    for(int j=0;j<strlen(str2);j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,1);}
         else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j])}
      }}}printf("%d\n",ans); }return 0;}