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<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const int inf2 = 1145141919;
const ld pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
	ll to, cost;
};
struct S {//???????????±?????\???????????°
	int from, to, cost;
};
bool operator<(S a, S b) { return a.cost < b.cost; }
bool operator>(S a, S b) { return a.cost > b.cost; }
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string a, b;
int dp[4000][4000];
signed main() {
	while (cin >> a >> b) {
		int n = a.size(), m = b.size();
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				dp[i][j] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) 
						dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
					else 
						dp[i][j] = 1;
					ans = max(ans, dp[i][j]);
				}
			}
		}
		cout << ans << endl;
	}
	getchar(); getchar();
}

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[6190000]={}, 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<algorithm>
#include<string>
#include<cstring>
using namespace std;

int dp[4001][4001];

int main()
{
  string a, b;
  while(cin >> a >> b)
  {
    int ans = 0;
    for(int i = 0; i < a.length(); i++)
    {
      for(int j = 0; j < b.length(); j++)
      {
        if(a[i + 1] == b[j + 1])
          ans = max(dp[i + 1][j + 1] = dp[i][j] + 1, ans);
        else
          dp[i + 1][j + 1] = 0;
      }
    }
    
    cout << ans << endl;
  }
}

C++: #include<stdio.h>
#include<string.h>
#define max(i,j) (i<j?j:i)
int dp[4001][4001];
int main(void){
	char s[4001],t[4001];
//	printf("%d\n",4000*4000);
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
//		dp[0][0]=s[0]==t[0];
		for(int i=0;i<4001;i++)dp[i][0]=dp[0][i]=0;
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=1;i<=sl;i++){
			for(int j=1;j<=tl;j++){
				if(s[i-1]==t[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
					ans = max(ans,dp[i][j]);
				}else dp[i][j]=0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int dp[4000][4000];

int count(string& a, string& b) {
    memset(dp, 0, sizeof(dp));
    int a_len = a.length();
    int b_len = b.length();
    dp[0][0] = 0;
    for (int i = 1; i < a_len; i++) dp[i][0] = 0;
    for (int j = 1; j < b_len; j++) dp[0][j] = 0;
    for (int i = 1; i < a_len; i++) {
        for (int j = 1; j < b_len; j++) {
            if (a[i] == b[j]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    int lcs_len = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len; j++) {
            if (dp[i][j] > lcs_len) {
                lcs_len = dp[i][j];
            }
        }
    }
    return lcs_len;
}

int main() {
    string a, b;
    while (cin >> a >> b) {
        cout << count(a, b) << endl;
    }
    return 0;
}

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

int dp[4010][4010], maxn;
string S, T;

int main() {
	while (cin >> S >> T) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < S.size(); i++) {
			for (int j = 0; j < T.size(); j++) {
				if (S[i] == T[j]) {
					dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
				}
			}
		}
		maxn = 0;
		for (int i = 0; i < S.size(); i++) {
			for (int j = 0; j < T.size(); j++) {
				maxn = max(maxn, dp[i][j]);
			}
		}
		cout << maxn << endl;
	}
}

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