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>
using namespace std;

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

int dp[2][4010];

int main(){
	string in1,in2;
	while(cin>>in1>>in2){
		int n = in1.size();
		int m = in2.size();
		int ret = 0;
		rep(i,2)rep(j,m+1)dp[i][j]=0;
		REP(i,1,n+1){
			int cur = i%2;
			int next = (i+1)%2;
			REP(j,1,m+1){
				if( in1[i-1]==in2[j-1] ){
					dp[next][j] = dp[cur][j-1] + 1;
					ret = max(ret,dp[next][j]);
				}
			}
			rep(i,m+1)dp[cur][i]=0;
		}
		printf("%d\n",ret);
	}
	return 0;
}

C++: class Main{
public static void main(){
Scanner sc=new Scanner(System.in);
for(;sc.hasNext();){
String s=sc.next();
String t=sc.next();
System.out.println(lcs(s,t).length());
}
}

	static String lcs(String s, String t){
		int m=s.length(), n=t.length();
		int[][] d=new int[n+1][m+1];
		int[][] v=new int[n+1][m+1];
		for(int j=1; j<=n; j++){
			for(int i=1; i<=m; i++){
				if(s.charAt(i-1)==t.charAt(j-1)){
					d[j][i]=d[j-1][i-1]+1;
					v[j][i]=0;
				}else if(d[j][i-1]>d[j-1][i]){
					d[j][i]=d[j][i-1];
					v[j][i]=+1;
				}else{
					d[j][i]=d[j-1][i];
					v[j][i]=-1;
				}
			}
		}
		String r="";
		for(int i=m, j=n; i>0&&j>0;){
			debug(i, j);
			if(v[j][i]>0)
				i--;
			else if(v[j][i]<0)
				j--;
			else{
				r=s.charAt(i-1)+r;
				i--;
				j--;
			}
		}
		return r;
	}

}

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

string s, t;
int l[4000][4000];
int m;

void list(string s,string t){
    for(int i = 0; i < s.length(); i++){
        for(int j = 0; j < t.length(); j++){
            if(s[i]==t[j]){
                if(i==0||j==0){
                    l[i][j]=1;
                }else{
                    l[i][j]=l[i-1][j-1]+1;
                }
            }
        }
    }
}

int search(){
    m = 0;
    for(int i = 0; i < s.length(); i++){
        for(int j = 0; j < t.length(); j++){
            if(l[i][j] >= m){
                m=l[i][j];
                l[i][j]=0;
            }else{
                l[i][j]=0;
            }
        }
    }
    return m;
}

int main(){
    for(;;){
        m = 0;
        if(cin >> s >> t){
            m = 0;
            list(s,t);
            m = 0;
            cout << search() << endl;
        }else{
            break;
        }
        m = 0;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

string lstrip(string s) {
    string ans = "";
    bool ok = false;
    FOE(c, s) {
        if (c != '0') {
            ans += c;
            ok = true;
        }
        else {
            if (ok) {
                ans += c;
            }
        }
    }
    return ans;
}

int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	while (cin >> s >> t) {
        vector<vector<int>> dp(5000, vector<int>(5000));
        FOR(i, 0, s.size()) {
            FOR(j, 0, t.size()) {
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                }
                else {
                    dp[i + 1][j + 1] = 0;
                };
            }
        }
        int ans = 0;
        FOR(i, 0, s.size()) {
            FOR(j, 0, t.size()) {
                ans = max(ans, dp[i][j]);
            }
        }
        print(ans);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    string s1,s2;
    while(cin>>s1>>s2)
    {
        int ans=0;
        vector<vector<int> >dp(s1.size(),vector<int>(s2.size(),0));
        REP(i,s2.size())if(s1[0]==s2[i])dp[0][i]=1;
        rep(i,1,s1.size())
        {
            REP(j,s2.size())
            {
                if(s1[i]==s2[j]){if(j==0)dp[i][j]++;else dp[i][j]+=dp[i-1][j-1]+1;}
                if(dp[i][j]>ans)ans=dp[i][j];
            }
        }
        cout<<ans<<endl;
    }
    
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	while(cin){
             cin>>s>>t;
		int roop1=0, save=0, ans = 0;
             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= 0;
				while (1){
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  for(string s,ss;cin>>s>>ss;){
    int dp[2][4001]={};
    int ans=0;
    for(int y=1;y<=ss.size();y++){
      for(int x=1;x<=s.size();x++){
	dp[y&1][x]=((ss[y]==s[x-1])?dp[(y-1)&1][x-1]+1:0);
	ans=max(ans,dp[y&1][x]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}