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 <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

int count(string& a, string& b) {
    int a_len = a.length();
    int b_len = b.length();
    int max_lcs = 0;
    int cur_lcs = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len && i + j < a_len; j++) {
            if (a[i+j] == b[j]) {
                cur_lcs++;
            } else {
                cur_lcs = 0;
            }
            max_lcs = max(max_lcs, cur_lcs);
        }
    }
    cur_lcs = 0;
    for (int i = 0; i < b_len; i++) {
        for (int j = 0; j < a_len && i + j < b_len; j++) {
            if (a[j] == b[i+j]) {
                cur_lcs++;
            } else {
                cur_lcs = 0;
            }
            max_lcs = max(max_lcs, cur_lcs);
        }
    }

    return max_lcs;
}

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

C++: #include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
char A[4002],B[4002];
int DP[4002][4002];


int main(){
	while(1){
		scanf("%s",A);
		scanf("%s",B);
		memset(DP,0,sizeof(DP));
		int ans=0;
		rep(i,strlen(A)){
			rep(j,strlen(B)){
				if(A[i]==B[j]){
					if(i!=0&&j!=0){
						DP[i][j]+=DP[i-1][j-1];
					}
					DP[i][j]++;
				}
				ans=max(ans,DP[i][j]);
			}
		}
	printf("%d\n",ans);
	}
}

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

string str[2];
short dp[4001][4001];

void solve()
{
	
	short ans = 0;


	if(str[0].length() > str[1].length()){
		swap(str[0],str[1]);
	}
	for(short i = 0; i < 4001; i++){
		for(short j = 0; j < 4001; j++)
			dp[j][i] = 0;
	}
	for(short i = 0; i < str[0].length(); i++){
		for(short j = 0; j < str[1].length(); j++){
			if(str[0][i] == str[1][j]){
				dp[j+1][i+1] += (dp[j][i]+1);
				ans = max(ans,dp[j+1][i+1]);
			}


		}
	}
	
/*
// dp表 確認(日本語)
// dp-table checking(English)

	cout << " ";
	for(short i = 0; i < str[0].length(); i++)
		cout << "  " << str[0][i];
	cout << endl;

	for(short i = 0; i < str[1].length(); i++){
		cout << str[1][i];
		for(short j = 0; j < str[0].length(); j++)
			prshortf("%3d", dp[i][j]);
		cout << endl;
	}
*/
	cout << ans << endl;

			
	
}


int main(void)
{
	while(cin >> str[0] >> str[1], !cin.eof()){
		solve();
	}

	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
#define max(a,b) ((a)>=(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))
int main() {
	string S,T;
	while(cin>>S) {
		cin>>T;
		int len=0;
		for(int i=0;i<S.size();i++) {
			for(int j=0;j<min(S.size()-i,T.size());j++) {
				int k;
				for(k=j;k<min(S.size()-i,T.size());k++) if(S[i+k]!=T[k]) break;
				len=max(len,k-j);
				j=k;
			}
		}
		for(int i=0;i<T.size();i++) {
			for(int j=0;j<min(T.size()-i,S.size());j++) {
				int k;
				for(k=j;k<min(T.size()-i,S.size());k++) if(T[i+k]!=S[k]) break;
				len=max(len,k-j);
				j=k;
			}
		}
		printf("%d\n",len);
	}
}

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(1){
        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 <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double EPS=1e-9;
const long long INF = 100001000010000100ll;

template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


string L, R;

int dp[4000+10][4000+10];

int main(){
	while(cin >> L >> R, L){
		memset(dp, 0, sizeof(dp));
		int ans=0;
		rp(i, R){
			rp(j, L){
				if(R[i]==L[j]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}else{
					dp[i][j]=0;
				}
				ans=max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;

	}

	return 0;

}

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

char A[4002],B[4002];
short int length[4000][4000];
int mmax[200],mcor = 0;
int main(){
	int i,j,lenA,lenB;
	while(cin >> A){
		cin >> B;
		lenA = strlen(A)-1;
		lenB = strlen(B)-1;
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				length[i][j] = -1;
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(length[i][j] >= 0)continue;
				for(int k = 0;i+k < lenA && i+k < lenB;k++){
						if(A[i+k] != B[i+k]){
							length[i][j] = k;
							break;
						}
				}
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(mmax[mcor] < length[i][j])
					mmax[mcor] = length[i][j];
			}
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		cout << mmax[i] << endl;
	}
	return 0;
}

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

#define loop(i,n) for(int i=0;i<n;i++)
int dp[4002][4002];

int main(){
  string a,b;
  while(cin>>a>>b){
    int m=0;
    loop(i,a.size())loop(j,b.size()){
      if(a[i]==b[j]){
        if(i==0||j==0)dp[i][j]=1;
        else dp[i][j]=dp[i-1][j-1]+1;
      }else{
        dp[i][j]=0;
      }
      m=max(m,dp[i][j]);
    }
    cout<<m<<endl;
  }
  return 0;
}