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<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;
    while(cin >> n){
    rep(i,0,4001){
        rep(j,0,4001){
        dp[i][j]=0;
        //cout << dp[i][j];
        }
    }
    cin >> m;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
            if(n[i]==m[j]){
                if(i==0||j==0)dp[i][j]=1;
                else dp[i][j]=dp[i-1][j-1]+1;
            }
        }
    }int ans=0;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
        ans=max(ans,dp[i][j]);
        //if(ans==6)cout << i << " " << j <<" ";
        }
    }
    cout << ans << endl;
    }
    return 0;
}

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

int main() {
	while(true){
		string s,t;
		cin>>s>>t;
		if(s){
			break;
		}
	
		int ans=0;
		for(int i=0;i<s.size();i++){
			for(int j=0;j<t.size();j++){
				if(s[i]==t[j]){
					int sum=0;
					sum++;
					for(int k=1;k<min(s.size(),t.size());k++){
						if(s[i+k]==t[j+k]){
							sum++;
						} else{
							ans=max(ans,sum);
							break;
						}
					}
				}
			}
		}
	
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 4001
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(scanf("%s",&s)){
  scanf("%s",&t);
  FOR(i,s.size()+1)
   FOR(j,t.size()+1) dp[i][j]=0;
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d",ma);
 }
}

int main(){
 solve();
 return 0;
}

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

using namespace std;

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

int ans, dp[4001][4001];

int main() {
	while (true) {
		ans = 0;
		memset(dp, 0, sizeof(dp));
		string str[2];
		cin >> str[0];
		if (str[0].empty()) break;
		cin >> str[1];
		REP(i, (int)str[0].size()) {
			REP(j, (int)str[1].size()) {
				if (str[0][i] == str[1][j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = ans < dp[i + 1][j + 1] ? dp[i + 1][j + 1] : ans;
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s1, s2;
        if(!(cin >> s1 >> s2))
            return 0;

        int n = s1.size();
        int m = s2.size();

        int ret = 0;
        vector<vector<int> > len(n, vector<int>(m, 0));
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                if(s1[i] == s2[j]){
                    if(i > 0 && j > 0)
                        len[i][j] = len[i-1][j-1] + 1;
                    else
                        len[i][j] = 1;
                    ret = max(ret, len[i][j]);
                }
            }
        }
        cout << ret << endl;
    }
}

C++: #include <cstdio>
#include <string>

using namespace std;

string scan_string() {
    char input[4000];

    if (scanf("%s", input) == EOF) {
        return "";
    }

    return string(input);
}

int main() {
    while (1) {
        int i;
        int n;
        string str1;
        string str2 = "";
        int max_sum = 0;

        str1 = scan_string();
        if (str1 == string("")) return 0;

        for (i=0;i<str1.length();i++) {
            str2 += " ";
        }
        str2 += scan_string();

        n = str2.length();
        for (i=0;i<n;i++) {
            int j;
            string str3 = str2.substr(i, n-i);
            int sum = 0;

            for (j=0;j<str1.length();j++) {
                if (str1[j] == str3[j]) {
                    sum++;
                } else {
                    if (max_sum < sum) max_sum = sum;
                    sum = 0;
                }
            }
            if (max_sum < sum) max_sum = sum;
        }

        printf("%d\n", max_sum);
    }
}

C++: #include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	string a, b;
	while (cin >> a >> b) {
		int sum = 0;
		for (int i = 0; i < a.length(); i++) {
			for (int j = 0; j < b.length(); j++) {
				if (a[i] == b[j]) {
					int sum2 = 0;
					int i2 = i, j2 = j;
					while (i2 < a.length() && j2 < b.length() && a[i2] == b[j2]) {
						sum2++;
						i2++;
						j2++;
					}
					sum = max(sum2, sum);
				}
			}
		}
		cout << sum << endl;
	}
}

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

char sa[4004], sb[4004];
int dp[4001][4001], mm;

void search(){
    mm = 0;
    for(int z = 0; z < 4000; z++){
        if( sb[z] ) dp[0][z] = (sa[0] == sb[z]);
        if( sa[z] ) dp[z][0] = (sa[z] == sb[0]);
    }
    for(int x = 0; sa[x+1]; x++){
        for(int y = 0; sb[y+1]; y++){
            dp[x+1][y+1] = (sa[x+1] == sb[y+1]) ?
                           dp[x][y] + 1 : 0;
            if( dp[x+1][y+1] > mm ) mm = dp[x+1][y+1];
        }
    }
    cout << mm << endl;
}

int main(){
    while( cin >> sa >> sb ){
        search();
    }
    return 0;
}