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++: #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;
}

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[strlen(str[0])+1][strlen(str[1])+1];
    int maxL = 0;
    for(int i = 0; i <= strlen(str[0]); i++) {data[i][0] = 0;}
    for(int j = 0; j <= strlen(str[1]); j++) {data[0][j] = 0;}

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

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

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

int dp[4001][4001];
char s1[4001], s2[4001];

int main() {
  while (scanf("%s", s1) != EOF) {
    scanf("%s", s2);
    int ans = 0;
    for (int i = 0; s1[i] != 0; i++) {
      for (int j = 0; s2[j] != 0; j++) {
        dp[i][j] = 0;
        if (s1[i] == s2[j]) {
          if (i == 0 || j == 0) dp[i][j] = 1;
          else dp[i][j] = dp[i - 1][j - 1] + 1;
        }
        ans = max(ans, dp[i][j]);
      }
    }
    printf("%d\n", ans);
  }
}

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;
		for(int i=0;i<(int)a.size();i++){
			for(int j=0;j<(int)b.size();j++){
				int temp=0;
				while(i+temp<(int)a.size()&&j+temp<(int)b.size()&&a[i+temp]==b[j+temp])	temp++;
				ans=max(ans,temp);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}