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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

#define MAX_S 4000
#define MAX_T 4000


int solve(string s,string t){
    static int dp[4001][4001];
    rep(i,s.size()+1)rep(j,t.size()+1)dp[i][j] = 0;
    int maxi=0;
    
    for(int i=1;i<s.size()+1;i++){
        for(int j=1;j<t.size()+1;j++){
            if(s[i-1]==t[j-1])  dp[i][j] = dp[i-1][j-1]+1;
            else                dp[i][j] = 0;
            maxi = max(maxi,dp[i][j]);
        }
    }
    
    return maxi;
}

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

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

string s, t;
char a[4001];
char b[4001];
int dp[4001][4001];

int main(){
	while(scanf("%s%s", a, b) != EOF){

		s = a;
		t = b;

		for(int i=0; i<4001; i++)
			for(int j=0; j<4001; j++)
				dp[i][j] = 0;

		int ans = 0;
		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;
				}else{
					dp[i][j] = 0;
				}
				ans = max(ans, dp[i][j]);
			}
		}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int moji[4001][4001];
int main(){
  string s,t;
  int ma;
  while(cin >> s >> t){
    fill_n(*moji,4001*4001,0);
    ma = 0;
    for(int i=0;i<s.size();i++){
      for(int j=0;j<t.size();j++){
	if(s[i] == t[j]){
	  moji[i][j] = (i==0)?1:moji[i-1][j-1]+1;
	  ma = max(ma,moji[i][j]);
	}
      }
    }
    cout << ma << 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.eof()){
	cin >> s >> t;
	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 <bits/stdc++.h>

using namespace std;

// 多次元 mul_array<int, 1, 2, 3> a
template <typename T, std::size_t... Ns>
struct index_reverse_for_array;
template <typename T, std::size_t N, std::size_t... Ns>
struct index_reverse_for_array<T, N, Ns...> { using type = std::array< typename index_reverse_for_array<T, Ns...>::type, N>; };
template <typename T, std::size_t N>
struct index_reverse_for_array<T, N> { using type = std::array<T, N>; };
template <class T, std::size_t... Ns> using mul_array = typename index_reverse_for_array<T, Ns...>::type;

// デバッグ用 dump マクロ
template <int N, int S> constexpr void temp_dump_split(const char *s, int i) { }
template <int N, int S, class V, class... Vs> constexpr void temp_dump_split(const char *s, int i, V v, Vs... vs) {
    if (i == S || s[i] == ',') { std::cerr << " = " << v << std::endl; temp_dump_split<N, S, Vs...>(s, i+1, vs...); return; }
    else if (s[i] != ' ') { cerr << s[i]; temp_dump_split<N, S, V, Vs...>(s, i+1, v, vs...); }
    else temp_dump_split<N, S, V, Vs...>(s, i+1, v, vs...);
}
template <std::size_t S, class... Ts>
static constexpr void temp_dump(const char (&s)[S], Ts... vs) { temp_dump_split<sizeof...(Ts), S, Ts...>(s, 0, vs...); }
#define dump(...) temp_dump(#__VA_ARGS__, __VA_ARGS__)

int main() {
    //cout << fixed << setprecision(10);

    //cout.setf(ios::right, ios::adjustfield);
    //cout.fill('0');
    //cout << setw(2) << "" << endl;

    string a, b;
    while (cin >> a >> b) {
        vector<vector<uint64_t>> dp(a.size());
        for (int i = 0; i < dp.size(); i++) {
            dp[i].resize(b.size());
            for (int j = 0; j < dp[i].size(); j++) {
                dp[i][j] = 0;
            }
        }
        uint64_t max = 0;
        for (int i = 0; i < dp.size(); i++) {
            for (int j = 0; j < dp[i].size(); j++) {
                if (a[i] == b[j]) {
                    if (i == 0 || j == 0)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = dp[i-1][j-1] + 1;

                    if (max < dp[i][j])
                        max = dp[i][j];
                }
            }
        }

        cout << max << endl;
    }


    return 0;
}

//cout << 1["hello"] << endl;

C++: #include <bits/stdc++.h>
using namespace std;

int dp[4001][4001];
char s[4001],t[4001];

int main(){
	while(scanf("%s%s",s,t) == 2){
		int ans = 0;
		int slen = strlen(s);
		int tlen = strlen(t);
		for(int i = 0; i < slen; i++){
			if(s[i] == t[0]){
				dp[0][i] = 1;
				ans = 1;
			}
			else{
				dp[0][i] = 0;
			}
		}
		for(int i = 0; i < tlen; i++){
			if(t[i] == s[0]){
				dp[i][0] = 1;
				ans = 1;
			}
			else{
				dp[i][0] = 0;
			}
		}

		for(int i = 1; i < tlen; i++){
			for(int j = 1; j < slen; j++){
				if(t[i] == s[j]){
					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 <string>
#include <cstring>
#include <algorithm>
using namespace std;

int dp[4001][4001];

int main(){
    
    string s, t;

    while(cin >> s >> t){
        memset(dp, -1, sizeof(dp));
        dp[0][0] = (s[0] == t[0]);
        for(int i = 1; i < s.size(); i++){
            for(int j = 1; j < t.size(); j++){
                if(s[i] == t[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j]  = 0;
            }
        }
        int maxi = 0;
        for(int i = 0; i < s.size(); i++){
            maxi = max(maxi, *max_element(dp[i], dp[i] + t.size()));
        }
        cout << maxi << endl;
    }
}