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 <string>
#include <iostream>
#include <algorithm>

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)

unsigned short dp[4010][4010];

int main(){
  int i,j;
  string s,t;

  while(cin >> s >> t){
    int N=s.length(),M=t.length(),res=0;

    rep(i,4010) rep(j,4010) dp[i][j] = 0;
    rep(i,N) rep(j,M){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
        res = max(res, (int)dp[i+1][j+1]);
      } else {
        dp[i+1][j+1] = 0;
      }
    }

    cout << res << endl;
//    cout << dp[N][M] << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long lint;

int main()
{
	char s[4096], t[4096];
	static int dp[2][4096];
	
	while (scanf("%s", s) == 1){
		scanf("%s", t);
		
		memset(dp, 0, sizeof(dp));
		
		int ans = 0;
		
		for (int i = 1; s[i - 1]; i++){
			for (int j = 1; t[j - 1]; j++){
				if (s[i - 1] == t[j - 1]) dp[i & 1][j] = max(dp[(i - 1) & 1][j - 1] + 1, max(dp[i & 1][j - 1], dp[(i - 1) & 1][j]));
				else dp[i & 1][j] = 0;
				ans = max(ans, dp[i & 1][j]);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: 
#include<iostream>
using namespace std;
int main()
{
  int ans,cnt;
  string s,t;
  while(cin>>s>>t){
    ans=0;
    for(int i=0;i<s.size();i++){
      cnt=0;
      for(int j=0;j<s.size()-i;j++){
	if(s[j+i]==t[j]){
	  cnt++;
	}else{
	  ans=max(ans,cnt);
	  cnt=0;
	}
      }
    }
    ans=max(ans,cnt);
    for(int i=0;i<t.size();i++){
      cnt=0;
      for(int j=0;j<t.size()-i;j++){
	if(t[i+j]==s[j]){
	  cnt++;
	}else{
	  ans=max(ans,cnt);
	  cnt=0;
	}
      }
    }
    ans=max(ans,cnt);
    cout<<ans<<endl;
  }
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int main() {

	string s, t;
	while (cin >> s >> t) {
		int dp[4040][4040];
		for (int i = 1; i <= s.size(); i++) {
			for (int j = 1; j <= t.size(); j++) {
				if (s[i - 1] == t[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < s.size() + 1; i++) {
			for (int j = 0; j < t.size() + 1; j++) {
				ans = max(ans, dp[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, 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 <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int dp[4000][4000];
char s[4004], t[4004];

int main() {
    while (cin >> s >> t) {
        for (int j = 0; j < 4000; ++j) {
            fill(dp[j], dp[j] + 4000, 0);
        }

        int sLen = strlen(s);
        int tLen = strlen(t);

        int ret = 0;

        for (int j = 0; j < sLen; ++j) {
            for (int k = 0; k < tLen; ++k) {
                if (s[j] != t[k]) {
                    dp[j][k] = 0;
                } else if (j == 0 || k == 0) {
                    dp[j][k] = 1;
                } else {
                    dp[j][k] = dp[j-1][k-1] + 1;
                }

                ret = max(ret, dp[j][k]);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

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;
}