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 <algorithm>
#include <vector>

std::string s1,s2;

std::vector<std::string> dat;

int main() {
    
    while(std::cin>>s1>>s2) {
        
        int ans=0;
        
        for(int i=0;i<s1.size();++i){
            for(int j=i;j<s1.size();++j)
                dat.emplace_back(s1.substr(i,j-i+1));
        }
        
        std::sort(dat.begin(),dat.end());
        
        for(int i=0;i<s2.size();++i){
            for(int j=i;j<s2.size();++j){
                std::string tmp=s2.substr(i,j-i+1);
                if(*(std::lower_bound(dat.begin(),dat.end(),tmp))==tmp)
                    ans=std::max(ans,j-i+1);
            }
        }
        
        std::cout<<ans<<std::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[2][strlen(str[1])+1];
    int maxL = 0;
    for(int i = 1; i <= strlen(str[0]); i++) {
      int p = i%2;

      data[p][0] = 0;
      if(i == 1)for(int k = 0; k <= strlen(str[1]); k++) data[1-p][k] = 0;

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

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

C++: #include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    vvll dp(4001, vll(4001, 0));
    while (cin >> s >> t) {
        ll ans = 0;
        REP(i, s.size()+1) REP(j, t.size()+1) dp[i][j] = 0;
        REP(i, s.size()) {
            REP(j, t.size()) {
                if (s[i] == t[j]) {
                    dp[i+1][j+1] = dp[i][j]+1;
                    chmax(ans, dp[i+1][j+1]);
                } else dp[i+1][j+1] = 0;
            }
        }
        cout << ans << '\n';
    }
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

char d[2][4005];
int dp[4001][4001];

int main(){
	while(scanf("%s%s",d[0],d[1])){
		for(int i=0;i<=4000;i++) for(int j=0;j<=4000;j++) dp[i][j]=0;
		int i,j;
		int res=0;
		for(i=0;d[0][i]!=0;i++){
			for(j=0;d[1][j]!=0;j++){
				if(d[0][i]==d[1][j]) dp[i+1][j+1]=dp[i][j]+1;
				res=max(res,dp[i+1][j+1]);
			}
		}
		printf("%d\n",res);
	}
}

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

int main() {
    string s1, s2;
    while (cin >> s1 >> s2) {
        if (s1.length() > s2.length()) {
            swap(s1, s2);
        }
        for (int i = s1.length(); i > 0; i--) {
            for (int j = 0; j + i - 1 < (int) s1.length(); j++) {
                string pattern = s1.substr(j, i);
                if (s2.find(pattern) != string::npos) {
                    cout << i << endl;
                    goto endMatch;
                }
            }
        }
        cout << 0 << endl;
    endMatch:;
    }
}

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;

short 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);

        short 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<stdio.h>
#include<string.h>
char a[4001];
char b[4001];
short dp[4001][4001];
int max(int a,int b){return a>b?a:b;}
int main(){
	while(scanf(" %s",a)!=EOF){
	scanf(" %s",b);
	int n=strlen(a);
	int m=strlen(b);
	int i,j;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)dp[i][j]=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(a[i]==b[j])dp[i+1][j+1]=dp[i][j]+1;
		}
	}
	int ans=0;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)ans=max(ans,dp[i][j]);
	printf("%d\n",ans);
	}
}

C++: #include<stdio.h>
#include<string.h>
typedef struct{
	int mx;
	int nx;
}data;
data d[4000][4000];
char a[4000],b[4000];
int i,j;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	while(scanf("%s",&a)!=EOF){
		scanf("%s",&b);
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++){
			d[i][j].nx=0;
			d[i][j].mx=0;
		}
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++){
				if(a[i]==b[j]){
					if(i>0&&j>0)d[i][j].nx=d[i-1][j-1].nx+1;
					else d[i][j].nx=1;
					if(i>0&&j>0)d[i][j].mx=max(d[i-1][j].mx,d[i][j-1].mx);
					else if(i>0)d[i][j].mx=d[i-1][0].mx;
					else if(j>0)d[i][j].mx=d[0][j-1].mx;
					d[i][j].mx=max(d[i][j].mx,d[i][j].nx);
				}
				else{
					d[i][j].nx=0;
					if(i>0&&j>0)d[i][j].mx=max(d[i-1][j].mx,d[i][j-1].mx);
					else if(i>0)d[i][j].mx=d[i-1][0].mx;
					else if(j>0)d[i][j].mx=d[0][j-1].mx;
				}
			}
		}
		/*for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j].mx);
			printf("\n");
		}
		printf("\n");
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j].nx);
			printf("\n");
		}*/
		printf("\n");
		printf("%d\n",d[strlen(a)-1][strlen(b)-1]);
	}
}