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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int n,m;
int memo[4444][4444];
bool done[4444][4444];
char s[4444],t[4444];

int dp(int i, int j){
    if(done[i][j]){
        return memo[i][j];
    }
    done[i][j] = true;
    if(i == n || j == m){
        memo[i][j] = 0;
    }else if(s[i] != t[j]){
        memo[i][j] = 0;
    }else{
        memo[i][j] = dp(i+1,j+1) + 1;
    }
    return memo[i][j];
}

int main(void){
    int i,j;
    ll ans;
    while(scanf("%s",s)!=EOF){
        fill(done[0],done[4444],false);
        ans = 0ll;
        scanf("%s",t);
        n = strlen(s); m = strlen(t);
        for(i=0; i<n; ++i){
            for(j=0; j<m; ++j){
                ans = max(ans,dp(i,j));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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


int main(){
    string a, b;
    while (cin >> a >> b){
	if (a.size() > b.size()) swap(a, b);
	int max = 0;
	for (int index = 0; index < a.size(); index++){
	    for (int size = a.size(); size >= 1; size--){
		string s = a.substr(index, size);
		if (b.find(s) != -1 && max < s.size()) max = s.size();
	    }
	}
	cout << max << endl;
    }
}

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){
	cin >> s >> 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++;
							cout << save[roop2] << ' ';
						}
						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 <cstdlib>
#include <iostream>
#include <set>
#include <string>
using namespace std;

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

const int MAX_LENGTH = 4000;
const unsigned long long base = 1000000007;
unsigned long long pow_hash[MAX_LENGTH + 1], hashes[MAX_LENGTH + 1];

inline void calc_pow() {
	pow_hash[0] = 1;
	for(int i = 0; i < MAX_LENGTH; ++i)
		pow_hash[i + 1] = pow_hash[i] * base;
}

inline void rolling_hash(const string& s) {
	hashes[0] = 0;
	for(int i = 0; i < s.size(); ++i)
		hashes[i + 1] = hashes[i] * base + s[i];
}

inline unsigned long long hash(int l, int r) {
	return hashes[r] - hashes[l] * pow_hash[r - l];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	calc_pow();

	for(string a, b; cin >> a;) {
		cin >> b;

		set<unsigned long long> s;

		rolling_hash(a);
		for(int l = 0; l < a.size(); ++l)
			for(int r = l + 1; r <= a.size(); ++r)
				s.insert(hash(l, r));

		int ans = 0;

		rolling_hash(b);
		for(int l = 0; l < b.size(); ++l)
			for(int r = l + 1; r <= b.size(); ++r)
				if(s.find(hash(l, r)) != s.end())
					chmax(ans, r - l);

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(cin){
             cin>>s>>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 <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int dp[4001][4001];
int main(void){
	while(1){
		string s1, s2; cin >> s1 >> s2;
		if(s1 == "") return 0;
		int s1size = s1.size(), s2size = s2.size();
		rep(i, 4001) dp[i][0] = dp[0][i] = 0;
		//dp[i][j] = dp[s1???i??????????????§][s2???j??????????????§] = (??£?¶???????????????????)

		int ans = 0;
		rep(i, s1size){
			rep(j, s2size){
				if(s1[i] == s2[j]){
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = max(ans, dp[i + 1][j + 1]);
				}else{
					dp[i + 1][j + 1] = 0;
				}

			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

string s,t;
int main() {
	while(cin>>s>>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]){
					int sum=0;
					sum++;
					for(int k=1;k<min(s.size(),t.size());k++){
						if(s[i+k]==t[j+k]){
							sum++;
						} else{
							ans=max(ans,sum);
							break;
						}
					}
				}
			}
		}
	
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	while(true){
		cin>>a>>b;
		if(cin.eof())	return 0;
		int ans=0;
		string A(a),B(b);
		for(int i=(int)a.size()-1;i>=0;i--){
			int tmp=0;
			for(int j=0;j<min(i+1,(int)b.size());j++){
				if(a[j]==b[j])	tmp++;
				else{
					ans=max(ans,tmp);
					tmp=0;
				}
			}
			a.erase(a.begin());
		}
		for(int i=(int)B.size()-1;i>=0;i--){
			int tmp=0;
			for(int j=0;j<min(i+1,(int)A.size());j++){
				if(A[j]==B[j])	tmp++;
				else{
					ans=max(ans,tmp);
					tmp=0;
				}
			}
			B.erase(B.begin());
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
	string a,b;
	while(cin >> a >> b){
		int ans = 0;
		for(int x = 0 ; x < 2 ; x++){
			for(int i = 0 ; i < a.size() ; i++){
				int len = 0;
				for(int j = 0 ; j < b.size() ; j++){
					if(a[i+len] == b[j])len++;
					else len = a[i] == b[j];
					ans = max(len,ans);
				}
			}
			swap(a,b);
		}
		cout << ans << endl;
	}
}
// a b c d e
// abcdef
// def

C++: #include <iostream>
#include <algorithm>
#include <string>
#define N 4000
using namespace std;
int n,m,dp[N][N],ans;
int main(){
  string A,B;
  while(cin>>A>>B){
    n=A.size();
    m=B.size();
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++) dp[i][j]=0;
    ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(A[i]==B[j]) dp[i+1][j+1]=dp[i][j]+1;
	ans=max(ans,dp[i+1][j+1]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}