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

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()

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<short> > dp(T.size() + 1, vector<short>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

				if (T[i - 1] == S[j - 1])
				{
					dp[i][j]++;
				}
			}
		}

		printf("%d\n", dp[T.size()][S.size()]);
	}

	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){
             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++;
						}
						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 <string>
using namespace std;
int main(){
	string s1,s2;
	while(cin>>s1>>s2){
		int ans=0;
		for(int i=0;i<s1.size();i++){
			while(true){
				if(i+ans>=s1.size())break;
				if(s2.find(s1.substr(i,ans+1),0)!=string::npos)ans++;
				else break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  string a,b;
  int c,d;
  int dp[2][5000],ans;
  while(cin>>a>>b){
    c=a.size(),d=b.size();
    ans=0;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=c;i++){
      for(int j=1;j<=d;j++){
	int ni=i%2,ri=1-i%2;
	//niは今のaの文字数が奇数か偶数か dpテーブルの使い回しのため
	//riはniじゃない方←前の結果のdpテーブル
	if(a[i-1]==b[j-1]){//一致したら前の状態の前の文字のdpテーブルから値を引っ張ってくる
	  dp[ni][j]=dp[ri][j-1]+1;
	}
	else dp[ni][j]=0;//違うなら打ち切る
	ans=max(ans,dp[ni][j]);
      }
    }
    cout<<ans<<endl;
  }
  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++;
	  ans=max(ans,cnt);
	}else{
	  cnt=0;
	}
      }
    }
    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++;
	  ans=max(ans,cnt);
	}else{
	  cnt=0;
	}
      }
    }
    cout<<ans<<endl;
  }
}

C++: #include<iostream>
main(){int a,c,i,j,k;for(std::string s,t;std::cin>>s>>t;printf("%d\n",a))for(a=k=0;k++<2;swap(s,t))for(i=s.size();i-->0;)for(j=c=0;j<s.size()-i;)s[j+i]-t[j++]?c=0:a=a>++c?a:c;}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    while (cin >> s >> t) {
        int ssize = s.length();
        int tsize = t.length();
        int low = 0;
        int high = max(ssize, tsize) + 1;
        while (high - low > 1) {
            int mid = (high + low) / 2;
            bool ok = false;
            if (mid > ssize || mid > tsize) {high = mid; continue;}
            rep(i, ssize - mid + 1)rep(j, tsize - mid + 1){
                if (s.substr(i, mid) == t.substr(j, mid)) {
                    ok = true;
                    break;
                }
            }
            if (ok) low = mid;
            else high = mid;
        }
        cout << low << endl;
    }
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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 mp make_pair
#define fi first
#define sc second
char s1[10000],s2[10000];
int dp[5000][5000];
int main(){
    while(scanf("%s%s",s1,s2) != EOF){
        int n = strlen(s1);
        int m = strlen(s2);

        REP(i,m){
            dp[0][i] = (s1[0] == s2[i]);
        }

        FOR(i,1,n){
            REP(j,m){
                if(j == 0){
                    dp[i][j] = (s1[i] == s2[j]);
                    continue;
                }
                if(s1[i] == s2[j]){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    continue;
                }
                dp[i][j] = 0;
            }
        }
        int maxi = 0;
        REP(i,n){
            REP(j,m){
                maxi = max(dp[i][j],maxi);
            }
        }
        printf("%d\n", maxi);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	while(true){
		string s1, s2;
		cin >> s1;
		if(cin.eof()){
			break;
		}
		cin >> s2;
		
    int maxcase_off1=0;
    int maxcase_off2=0;
    int maxcase_len=0;
    for(int off = -(int)s1.size(); off <= (int)s2.size(); off++) {
        int len = 0;
        for(int i = max(off, 0); i < min(s1.size()+off, s2.size()); i++) {
            if(len > maxcase_len) {
                maxcase_off1 = i-len-off;
                maxcase_off2 = i-len;
                maxcase_len = len;
            }
            if(s1[i-off] != s2[i]) {
                len = 0;
            } else {
                len++;
            }
        }
    }
    cout << maxcase_len << endl;

		
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math>
int main(void){
	char s[4001],t[4001];
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=0;i+ans<sl;i++){
			for(int j=0;j+ans<tl;j++){
				if(s[i]==t[j]){
					for(int k=1;j+k<tl && i+k<sl;k++){
						ans = max(ans,k);
						if(s[i+k]!=t[j+k])break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}