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 <cstring>
using namespace std;
 
short 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<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string A,B;
    while(cin>>A>>B){
        int ans=0;
        if(A.size()<B.size())swap(A,B);
        for(int i=-(int)(B.size())+1;i<(int)A.size();i++){
            int cou=0;
            for(int j=0;j<B.size();j++){
                if(0<=i+j&&i+j<A.size()){
                    if(A[i+j]==B[j])cou++;
                    else cou=0;
                    ans=max(ans,cou);
                }
            }
        }
        cout<<ans<<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];
    data[0][0] = data[1][0] = 0;
    int maxL = 0;
    for(int i = 1; i <= strlen(str[0]); i++) {
      int p = i%2;
      for(int j = 1; j <= strlen(str[1]); j++) {
	if(str[0][i-1] == str[1][j-1]) 
	  if(i == 1) data[p][j] = 1;
	  else       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++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(cin>>s>>t){
        cin>>s>>t;
	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>

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int dp[4005][4005];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    str n,m;
    rep(i,0,4000)rep(j,0,4000)dp[i][j]=0;
    cin >> n >> m;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
            if(n[i]==m[j]&&i>0&&j>0){
                dp[i][j]+=dp[i-1][j-1]+1;
            }else if(n[i]==m[j]){
                dp[i][j]=1;
            }else{
                dp[i][j]=max(dp[i][j-1],dp[i][j]);
            }
        }
    }int ans=0;
    rep(i,0,n.size()){
        ans=max(ans,dp[i][m.size()-1]);
    }
    cout << ans << endl;
    return 0;
}

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

void swap(string& a, string& b){
	string s = a;
	a = b;
	b = s;
	return;
}

int main(){
	string s1, s2;
	int res, p1, p2, count;
	int size1, size2;
	
	while(cin >> s1){
		cin >> s2;
		
		res = 0;
		if(s1.size() > s2.size()) swap(s1, s2);
		
		size1 = s1.size(); size2 = s2.size();
		
		for(int i = 1 - size1; i < size2; i++){
			p1 = (i >= 0)? 0 : -i;//start position of s1
			count = 0;
			p2 = 0;
			while(p1 < size1 && p2 < size2){
				if(s1[p1] == s2[p2]) count++;
				else{
					if(res < count) res = count;
					count = 0;
				}
				p1++; p2++;
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s1,s2;
	cin >> s1;
	if(cin.eof()) break;
	cin >> s2;
	int ans = 0;
	int h = s1.size()+1;
	int l = 0;
	int m = (h+l)/2;
	REP(i,20){
	    bool flg = false;
	    set<string> ss;
	    REP(i,s1.size()-m+1){
		ss.insert(s1.substr(i,m));
	    }

	    REP(i,s2.size()-m+1){
		if(ss.find(s2.substr(i,m)) != ss.end()){
		    flg = true;
		}
	    }
	    if(flg){
		l = m;
//		printf("m = %d\n",m);
	    }else{
		h = m;
	    }
	    m = (h+l)/2;
	}
	cout << m << endl;

    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s1,s2;
	while(cin >> s1 >> s2){
	int t[4001][4001];
	for(int i=0;i<=s1.length();i++){
		t[0][i]=0;
	}
	for(int j=0;j<=s2.length();j++){
		t[j][0]=0;
	}
	for(int i=1;i<=s1.length();i++){
		for(int j=1;j<=s2.length();j++){
			if(s1[i-1]==s2[j-1])t[i][j]=t[i-1][j-1]+1;
			else t[i][j]=0;
		}
	}
	int ans=0;
	for(int i=1;i<=s1.length();i++){
		for(int j=1;j<=s2.length();j++){
			ans=max(ans,t[i][j]);
		}
	}
	cout << ans << "\n";
	}
	return 0;
}

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

short dp[4002][4002];

int main(){
  string a, b;

  while(cin >> a >> b){
    int n = a.length();
    int m = b.length();

    memset(dp, 0, sizeof(dp));
    short res = 0;

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= m; j++){
        if(a[i - 1] == b[j - 1]){
          dp[i][j] = dp[i - 1][j - 1] + 1;
          res = max(res, dp[i][j]);
        }
      }
    }

    cout << res << endl;
  }
}