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++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	while (cin >> s) {
		cin >> t;
		int n = s.size(), m = t.size();
		vvi table(n, vi(m, 0));
		REP(i, n) {
			if (s[i] == t[0])table[i][0] = 1;
		}
		REP(i, m) {
			if (s[0] == t[i])table[0][i] = 1;
		}
		REP(i, n - 1) {
			REP(j, m - 1) {
				if (s[i + 1] == t[j + 1])table[i + 1][j + 1] = table[i][j] + 1;
				else table[i + 1][j + 1] = 0;
			}
		}
		int ans = -INF;
		REP(i, n) {
			REP(j, m) {
				ans = max(ans, table[i][j]);
			}
		}
		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=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s=="")
		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= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	
	return 0;
}

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

std::string s1,s2;

std::vector<std::string> dat;

int main() {
    
    while(std::cin>>s1>>s2) {
        
        int ans=0;
        
        for(int i=0;i<s1.size();++i){
            for(int j=i;j<s1.size();++j)
                dat.emplace_back(s1.substr(i,j-i+1));
        }
        
        std::sort(dat.begin(),dat.end());
        
        for(int i=0;i<s2.size();++i){
            for(int j=i;j<s2.size();++j){
                std::string tmp=s2.substr(i,j-i+1);
                if(*(std::lower_bound(dat.begin(),dat.end(),tmp))==tmp)
                    ans=std::max(ans,j-i+1);
            }
        }
        
        std::cout<<ans<<std::endl;
    }
    
    return 0;
}

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

int main() {
  while(1) {
    char str[2][4001];
    int state;
    state = scanf("%s\n", str[0]);
    if(state == EOF) break;
    scanf("%s\n", str[1]);

    int data[2][strlen(str[1])+1];
    int maxL = 0;
    for(int i = 1; i <= strlen(str[0]); i++) {
      int p = i%2;

      data[p][0] = 0;
      if(i == 1)for(int k = 0; k <= strlen(str[1]); k++) data[1-p][k] = 0;

      for(int j = 1; j <= strlen(str[1]); j++) {
	if(str[0][i-1] == str[1][j-1]) data[p][j] = data[1-p][j-1]+1;
	else     data[p][j] = 0;

	if(data[p][j] > maxL) maxL = data[p][j];
      }
    }
    cout << maxL << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    vvll dp(4001, vll(4001, 0));
    while (cin >> s >> t) {
        ll ans = 0;
        REP(i, s.size()+1) REP(j, t.size()+1) dp[i][j] = 0;
        REP(i, s.size()) {
            REP(j, t.size()) {
                if (s[i] == t[j]) {
                    dp[i+1][j+1] = dp[i][j]+1;
                    chmax(ans, dp[i+1][j+1]);
                } else dp[i+1][j+1] = 0;
            }
        }
        cout << ans << '\n';
    }
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

char d[2][4005];
int dp[4001][4001];

int main(){
	while(scanf("%s%s",d[0],d[1])){
		for(int i=0;i<=4000;i++) for(int j=0;j<=4000;j++) dp[i][j]=0;
		int i,j;
		int res=0;
		for(i=0;d[0][i]!=0;i++){
			for(j=0;d[1][j]!=0;j++){
				if(d[0][i]==d[1][j]) dp[i+1][j+1]=dp[i][j]+1;
				res=max(res,dp[i+1][j+1]);
			}
		}
		printf("%d\n",res);
	}
}

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

int main() {
    string s1, s2;
    while (cin >> s1 >> s2) {
        if (s1.length() > s2.length()) {
            swap(s1, s2);
        }
        for (int i = s1.length(); i > 0; i--) {
            for (int j = 0; j + i - 1 < (int) s1.length(); j++) {
                string pattern = s1.substr(j, i);
                if (s2.find(pattern) != string::npos) {
                    cout << i << endl;
                    goto endMatch;
                }
            }
        }
        cout << 0 << endl;
    endMatch:;
    }
}