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
var dp [4001][4001]int

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()

		for i := range dp {
			for j := range dp[i] {
				dp[i][j] = 0
			}
		}

		dp[0][0] = 0
		for i := range S {
			for j := range T {
				if S[i] == T[j] {
					dp[i+1][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++: 
// @snippet<sh19910711/contest:headers.cpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <limits>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

// @snippet<sh19910711/contest:solution/interface.cpp>
namespace solution {
    class ISolution {
    public:
        virtual void init() {};
        virtual bool input() { return false; };
        virtual void output() {};
        virtual int run() = 0;
    };
}

// @snippet<sh19910711/contest:text/suffix_array.cpp>
namespace text {
    class SuffixArray {
    public:
        typedef std::vector<int> VI;
        std::string s;
        int n;
        int k;
        VI sa;
        VI rank;
        void build() {
            int maxlen = n;
            for ( int i = 0; i < n; ++ i ) {
                rank[i] = s[i];
                maxlen = std::max( maxlen, s[i] + 1 );
            }
            VI cnt(maxlen, 0);
            for ( int i = 0; i < n; ++ i )
                cnt[rank[i]] ++;
            for ( int i = 1; i < maxlen; ++ i )
                cnt[i] += cnt[i-1];
            for ( int i = 0; i < n; ++ i )
                sa[--cnt[rank[i]]] = i;

            for ( k = 1; k < n; k *= 2 ) {
                VI r = rank;
                rank[sa[0]] = 0;
                for ( int i = 1; i < n; ++ i ) {
                    int s1 = sa[i-1];
                    int s2 = sa[i];
                    rank[s2] = r[s1] == r[s2] && std::max( s1, s2 ) + k < n && r[s1+k/2] == r[s2+k/2] ? rank[s1] : i;
                }
                for ( int i = 0; i < n; ++ i )
                    cnt[i] = i;
                VI s = sa;
                for ( int i = 0; i < n; ++ i ) {
                    int s1 = s[i] - k;
                    if ( s1 >= 0 )
                        sa[cnt[rank[s1]]++] = s1;
                }
            }
        }
        SuffixArray() {
            init("");
        }
        SuffixArray( const std::string& s_ ) {
            init(s_);
        }
        void init( const std::string& s_ ) {
            s = s_;
            n = s.size();
            sa.resize(n);
            rank.resize(n+1);
        }
        VI::iterator begin() {
            return sa.begin();
        }
        VI::iterator end() {
            return sa.end();
        }
        int& operator []( int k ) {
            return sa[k];
        }

        bool find( const std::string& key ) {
            int lb = -1, ub = n;
            while ( ub - lb > 1 ) {
                int mid = ( lb + ub ) / 2;
                std::string t = s.substr( sa[mid] );
                if ( t.substr( 0, key.size() ) == key ) {
                    return true;
                } else if ( t < key ) {
                    lb = mid;
                } else {
                    ub = mid;
                }
            }
            return false;
        }
    };
}



// @snippet<sh19910711/contest:solution/solution.cpp>
namespace solution {
    using namespace std;
    string A, B;
    text::SuffixArray sa;
    class Solution: public ISolution {
    public:
        bool input() {
            return cin >> A >> B;
        }
        int search( string s ) {
            int length = 0;
            int n = s.size();
            for ( int i = 0; i + length < n; ) {
                if ( sa.find( s.substr( i, length + 1 ) ) ) {
                    length ++;
                } else {
                    i ++;
                }
            }
            return length;
        }
        void solve() {
            sa.init(A);
            sa.build();
            cout << search(B) << endl;
        }
        int run() {
            while ( init(), input() ) {
                solve();
                output();
            }
            return 0;
        }
    };
}


// @snippet<sh19910711/contest:main.cpp>

int main() {
    return solution::Solution().run();
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    string s1,s2;
	int dp[4001][4001];
	for(int i=0;i<=4000;i++){
		dp[i][0]=0;
		dp[0][i]=0;
	}
	while(EOF){
		int ans=0;
		cin >> s1 >> s2;
		for(int i=1;i<=s1.length();i++){
			for(int j=1;j<=s2.length();j++){
				if(s1[i-1]==s2[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else dp[i][j]=0;
				ans=max(ans,dp[i][j]);
			}
		}
	printf("%d\n",ans);
	}
    return 0;
}

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

using namespace std;

string S1, S2;

int longest(string a, string b) {
	int res = 0;
	int nagasa = 0;
	for (int i = 0; i < min(a.size(), b.size()); i++) {
		if (a[i] == b[i])nagasa++;
		else {
			res = max(res, nagasa);
			nagasa = 0;
		}
	}
	res = max(res, nagasa);
	return res;
}

int main() {
	while (cin >> S1 >> S2) {
		string a = S1, b = S2;
		int ans = 0;
		while (b.size()) {
			ans = max(ans, longest(S1, b));
			b.erase(b.begin());
		}
		while (a.size()) {
			ans = max(ans, longest(a, S2));
			a.erase(a.begin());
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main(){
    while (1){
	string a, b;
	cin >> a >> b;
	if (cin.eof()) break;

	if (a.size() > b.size()) swap(a, b);

	vector<int> ss;
	int size, index, max = 0;
	for (index = 0; index < a.size(); index++){
	    for (size = a.size(); size >= 1; size--){
		if (b.find(a.substr(index, size)) != -1){
		    if (max < a.substr(index, size).size())
			max = a.substr(index, size).size();
		}
	    }
	}
	cout << max << endl;
    }
}