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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int dp[4010][4010];
string str1, str2;

int main() {
    while (cin >> str1 >> str2) {
        int res = 0;
        
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < str1.size(); ++i) 
            for (int j = 0; j < str2.size(); ++j) 
                if (str1[i] == str2[j]) 
                    dp[i][j] = 1, res = 1;
        
        for (int i = 0; i < str1.size()-1; ++i) {
            for (int j = 0; j < str2.size()-1; ++j) {
                if (str1[i+1] == str2[j+1] && dp[i][j] != -1) {
                    chmax(dp[i+1][j+1], dp[i][j] + 1);
                    chmax(res, dp[i+1][j+1]);
                }
            }
        }
        
        cout << res << endl;
    }
    return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2, save[1000000], ans;
		cin>>s;
		cin>>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>
#include <algorithm>
using namespace std;
int main(){
	string a,b;
	while(cin>>a>>b){
		int n=0;
		int la=a.size();
		int lb=b.size();
		for(int i=0;i<la;i++){
			for(int j=0;j<lb;j++){
				int k=0,m=0;
				do{
					if(a[i+k]==b[j+k]){
						k++;
						m=1;
						if(i+k>la-1||j+k>lb-1){
							m=0;
						}
					}
					else{
						m=0;
					}
				}while(m==1);
				n=max(n,k);
			}
		}
		cout<<n<<endl;
	}
    return 0;
}

C++: #include <string>
#include <iostream>
#include <algorithm>

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)

unsigned int dp[4010][4010];

int main(){
  int i,j;
  string s,t;

  while(cin >> s >> t){
    int N=s.length(),M=t.length(),res=0;

    rep(i,4010) rep(j,4010) dp[i][j] = 0;
    rep(i,N) rep(j,M){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        int tmp = max(dp[i][j+1],dp[i+1][j]);
        res = max(res,tmp);
        dp[i+1][j+1] = 0;
      }
    }

    cout << res << endl;
//    cout << dp[N][M] << 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<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; 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> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


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]; }

int dp[4002][4002];
int main(){
	string a,b;
	while(cin >> a >> b){
		memset(dp,0,sizeof(dp));
	int as=a.size();
	a+='-';
	int bs=b.size();
	b+='^';
	int ans=0;
	for(int i=0;i<=as;i++){
		for(int j=0;j<bs;j++){
			if(a[i+1]==b[j+1]){
				dp[i+1][j+1]=dp[i][j]+1;
			}else{
				dp[i+1][j+1]=0;
			}
			ans=max(ans,dp[i+1][j+1]);

		}
	}
	cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define STR string

using namespace std;

string s,t;
long long dp[10000][10000];

void solve(){
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else{
                dp[i+1][j+1]=(dp[i][j+1]>dp[i+1][j])?dp[i][j+1]:dp[i+1][j];
            }
        }
    }
cout << dp[s.size()][t.size()] << endl;
}


int main(){
while(1){
cin >> s >>t;
if(s=="EOF")break;
solve();
}
return 0;
}