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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s, t;
int dp[10000][10000];

int main(){
	int ans = -1;
	cin >> s >> t;
	REP(i, s.size()){
		REP(j, t.size()){
			if (s[i] == t[j]){
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			ans = max(ans, dp[i + 1][j + 1]);
		}
	}
	cout << ans << endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <queue>
using namespace std;

int main()
{
	int lt,ls,lmax;
	char ct[4001],cs[4001];
	map<string,bool> made;
	string t,s,stemp[2];
	queue<string> que;

	while(scanf("%s",ct)  != EOF){
		scanf("%s",cs);
		t.append(ct);
		s.append(cs);

		if(t.length() < s.length()){
			t.swap(s);
		}

		que.push(s);
		made.insert(make_pair(s,true));
		while(!que.empty()){
			stemp[0] = que.front();
			stemp[1] = stemp[0];
			if(t.find(stemp[0]) != string::npos){
				break;
			}

			stemp[0].erase(stemp[0].begin());
			stemp[1].erase(stemp[0].length(),1);
			for(int c = 0; c < 2; c++){
				if(made.find(stemp[c]) == made.end()){
					made.insert(make_pair(stemp[c],true));
					que.push(stemp[c]);
				}
			}
			que.pop();
		}

		if(que.empty()){
			cout << 0 << endl;
		}
		else{
			cout << que.front().length() << endl;
			while(!que.empty()){
				que.pop();
			}
			made.clear();
			t.clear();
			s.clear();
		}
	}

	return 0;
}

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

char A[4002],B[4002];
short int length[4000][4000];
int mmax[200],mcor = 0;
int main(){
	int i,j,lenA,lenB;
	int X;
	while(cin >> X){
		cin >> A;
		cin >> B;
		lenA = strlen(A)-1;
		lenB = strlen(B)-1;
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				length[i][j] = -1;
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(length[i][j] >= 0)continue;
				for(int k = 0;i+k < lenA && i+k < lenB;k++){
						if(A[i+k] != B[i+k]){
							length[i][j] = k;
							break;
						}
				}
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(mmax[mcor] < length[i][j])
					mmax[mcor] = length[i][j];
			}
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		cout << mmax[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
	int a,b;
	while(1){
		memset(len,0,sizeof(len));
		string str;
		string str2;
		int ans=0;
		cin >> str;
		if(str=="EOF")break;
		cin >> str2;
		for(a=0;a<str.size();a++){
			int res=0;
			string tmp= str.substr(a, str.size()-a);
			for(b=0;b<min(tmp.size(),str2.size());b++){
				if(tmp[b]==str2[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str2.size())-1==b)ans=max(res,ans);
			}
		}
		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){
	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<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  string str;
  while(cin>>str){
    string str2;cin>>str2;
    if(str.size()>str2.size()){
      string tmp=str;
      str=str2;
      str2=tmp;
    }
    int ans=0;
    for(int i=str.size();i>0;i--){
      for(int j=0;j<=str.size()-i;j++){
	for(int k=0;k<=str2.size()-i;k++){
	  if((str.substr(j,i)).compare((str2.substr(k,i)))==0){
	    ans=i;
	    break;
	  }
	}
	if(ans)break;
      }
      if(ans)break;
    }
    cout<<ans<<endl;
  }
  return 0;
}