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>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int dp[4000][4000];
int main(){
    string str1;
    while(cin>>str1){
        string str2;
        cin>>str2;
        rep(i,str1.length()+1)
            rep(j,str2.length()+1){
                if(j>0&&i>0){
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                    if(str1[i-1]==str2[j-1])dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
                }
            }
        cout<<dp[str1.length()][str2.length()]<<endl;
        rep(i,str1.length()+1)
            rep(j,str2.length()+1)dp[i][j]=0;
    }
}

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

#define MAXLEN 4001

using namespace std;

string str[2];
int len[2],lng,sht;

int main(void)
{
	while(true)
	{
		cin >> str[0];
		if(cin.eof())
		{
			exit(0);
		}
		cin >> str[1];
		len[0] = str[0].length();
		len[1] = str[1].length();
		if(len[0] < len[1])
		{
			lng = 1;
			sht = 0;
		}
		else
		{
			lng = 0;
			sht = 1;
		}
		int count_len_max = 0;
		for(int offset = 0;offset < len[lng];offset++)
		{
			int count_len = 0;
			for(int count = 0;count < len[sht];count++)
			{
				if((count + offset) < len[lng])
				{
					if(str[lng][(count + offset)] == str[sht][count])
					{
						count_len++;
					}
					else
					{
						count_len = 0;
					}
					count_len_max = max(count_len_max,count_len);
				}
			}
		}
		for(int offset = 0;offset < len[sht];offset++)
		{
			int count_len = 0;
			for(int count = 0;count < len[lng];count++)
			{
				if((count + offset) < len[sht])
				{
					if(str[sht][(count + offset)] == str[lng][count])
					{
						count_len++;
					}
					else
					{
						count_len = 0;
					}
					count_len_max = max(count_len_max,count_len);
				}
			}
		}
		
		cout << count_len_max << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int dp[4001][4001];
int main(){
    string str1;
    while(cin>>str1){
        string str2;
        cin>>str2;
        rep(i,str1.length()+1)
            rep(j,str2.length()+1){
                if(j>0&&i>0){
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                    if(str1[i-1]==str2[j-1])dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
                }
            }
        cout<<dp[str1.length()][str2.length()]<<endl;
        rep(i,str1.length()+1)
            rep(j,str2.length()+1)dp[i][j]=0;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a,b;
int n,m;

int solve(int x, int y){
    int ret=0,cnt=0;
    while(x < n && y < m){
        if(a[x] == b[y]){
            cnt++;
        }else{
            ret = max(ret,cnt);
            cnt = 0;
        }
        x++;
        y++;
    }
    return max(ret,cnt);
}

int main(){
    while(cin >> a >> b){
        int x=0,y=0,t=1,tmp=0,ret=0;
        n=a.size();
        m=b.size();
        for(int i=0;i<n;i++){
            ret = max(ret,solve(i,0));
        }
        for(int i=0;i<m;i++){
            ret = max(ret,solve(0,i));
        }
        cout << ret << endl;
    }
}

C++: #include<bits/stdc++.h>
#define lld long long int
#define str string


using namespace std;

lld f();
lld ster=0,leg,leg2,ans=0,ans2=0,memo[10000000];

str moji,moji2,cut;

int main(){
while(1){
        fill(memo,memo+10000,0);
    cin >> moji ;
    if(moji=="EOF")break;
    cin >> moji2 ;
    leg=moji.size();
    leg2=moji2.size();

    cout << f() << endl;
    ans=0;
    ans2=0;
}
return 0;
}

lld f(){
    for(int a=0;a<leg;a++){
        if(memo[moji[a]]!=1)ster=1;
            for(int b=1+ster;b<leg-a;b++){
        cut = moji.substr(a,b);
        if(moji2.find(cut)==-1)break;
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    memo[moji[a]]=1;
    }
    return ans2;
}

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 <iostream>
#include <cstring>

#define MAX 4000

short dp[MAX+1][MAX+1];

char buffer1[MAX];
char buffer2[MAX];

int main(int argc, char *argv[]){
  while(std::cin >> buffer1){
    int len1, len2,i,j, max = 0;
    
    std::cin >> buffer2;

    len1 = strlen(buffer1);
    len2 = strlen(buffer2);
    
    for(i = 0; i < len1+1; i++){
      for(j = 0; j < len2+1; j++){
	dp[i][j] = 0;
      }
    }

    for(i = 0; i < len1; i++){
      for(j = 0; j < len2; j++){
	if(buffer1[i] == buffer2[j]){
	  dp[i+1][j+1] = dp[i][j] + 1;
	  if(max < dp[i+1][j+1]){
	    max = dp[i+1][j+1];
	  }
	}
      }
    }

    std::cout << max << std::endl;
    
  }
  
  return 0;    
}