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] = 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++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0, save[1000000]={}, ans = 0;
		cin>>s;
		cin>>t;
		if(cin.eof())
		break;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save[roop2] = 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save[roop2] += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(cin.eof()){
	cin >> s >> t;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save[roop2] = 0;
				while (1){
					if (s[i + roop1] == 0|| t[j + roop1] ==0){
						break;
					}
					else{
					if (s[i + roop1] == t[j + roop1]){
							save[roop2] += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0, save[1000000]={}, ans = 0;
		cin>>s;
		cin>>t;
		if(cin.eof())
		break;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save[roop2] = 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save[roop2] += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

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;
}