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++: //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int dp[5000][5000];
int n,m;
string a,b;

int main(){
while(cin>>a>>b){
if(a.size()>b.size())swap(a,b);
n=a.size();
m=b.size();

int ans=0;
rep(i,5000)rep(j,5000)dp[i][j]=0;

for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	if(a[i-1]==b[j-1]){
		//	dp[i][j]=1;
		dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
	}
	ans=max(ans,dp[i][j]);


/*
		if(i&1){//2,4,6,8...番目
			if(a[i]==b[j]){
				if(j-1>=0)
				dp[1][j]=max(dp[1][j],dp[0][j-1]+1);
				else dp[1][j]=max(dp[1][j],1);
				ans=max(ans,dp[1][j]);
			}
		}
		else{//1,3,5,7,9...番目
			if(a[i]==b[j]){
				if(j-1>=0)
				dp[0][j]=(dp[0][j],dp[1][j-1]+1);
				else dp[0][j]=max(dp[0][j],1);
				ans=max(ans,dp[0][j]);
			}
		}
*/

	}
}

cout<<ans<<endl;
}


	return 0;
}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<short> > dp(T.size() + 1, vector<short>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

				if (T[i] == S[j])
				{
					dp[i][j]++;
				}
			}
		}

		printf("%d\n", dp[T.size()][S.size()]);
	}

	return 0;
}

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

using namespace std;

int main()
{
	for(string s1,s2;cin>>s1>>s2;){
		int len1=s1.length(),len2=s2.length();
		int lcslen=0;
		for(int i=-len2+1;i<len2;i++){
			int cnt=0;
			for(int j=max(0,-i);j<min(len1,len2-i);j++){
				if(s1[j]==s2[i+j])	cnt++;
				else	lcslen=max(lcslen,cnt),cnt=0;
			}
			lcslen=max(lcslen,cnt);
		}
		cout<<lcslen<<endl;
	}

	return 0;
}

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

int main(){
	string s,t;
while(cin>>s>>t){
	cout<<s<<endl<<t<<endl;
	static int ans[4002][4002]={0},big=0;
	for(int i=0;i<4002;i++)for(int j=0;j<4002;j++)ans[i][j]=0;
	big=0;
	int ss=s.size(),ts=t.size();
	for(int i=ss-1;i>=0;i--){
		for(int j=ts-1;j>=0;j--){
			if(s[i]==t[j]){
				ans[i][j]=ans[i+1][j+1]+1;
				if(big<ans[i][j])big=ans[i][j];
			}
		}
	}
	cout<<big<<endl;
}
}

C++: #include <stdio.h>
#include <string.h>

int main(void){
	char str1[5001]={0},str2[5001]={0};
	str1[0]='0';
	str2[0]='0';
	
	while(scanf("%s",&str1[1])!=EOF){
		int dp[2][5002]={0};
		int i,j,st1,st2,max=0,f=0;
		
		scanf("%s",&str2[1]);
		
		st1=strlen(str1);
		st2=strlen(str2);
		
		for(i=1;i<st1;i++){
			for(j=1;j<st2;j++){
				if(str1[i]==str2[j]){
					dp[f][j]=dp[1-f][j-1]+1;
				}
				else dp[f][j]=0;
				
				if(dp[f][j]>max)max=dp[f][j];
			}
			if(f)f=0;
			else f=1;
		}
		printf("%d\n",max);
	}
	
	return 0;
}

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 dp[4001][4001];

int main(){
    
    string s, t;

    while(cin >> s >> t){
        memset(dp, -1, sizeof(dp));
        dp[0][0] = (s[0] == t[0]);
        for(int i = 1; i < s.size(); i++){
            for(int j = 1; j < t.size(); j++){
                if(s[i] == t[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j]  = 0;
            }
        }
        int maxi = 0;
        for(int i = 0; i < s.size(); i++){
            maxi = max(maxi, *max_element(dp[i], dp[i] + t.size()));
        }
        cout << maxi << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<typename T>
void maxs(T &a, const T &b){
    if(a < b) a = b;
}

int dp[4010][4010];

int main(){
    string a,b;
    while(cin >> a >> b){
        REP(i,4010) memset(dp[i],0,sizeof(dp[i]));
        int ans = 0;
        for (int i = 0; i < sz(a); i++) {
            for (int j = 0; j < sz(b); j++) {
                if (a[i] == b[j]) {
                    dp[i+1][j+1] = dp[i][j] + 1;
                    ans = max(ans, dp[i+1][j+1]);
                }
            }
        }
        // for (int i = 0; i <= sz(a); i++) {
        //     if (i > 0) 
        //         cout << a[i - 1] << ": ";
        //     for (int j = 0; j <= sz(b); j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        cout << ans << endl;
    }
}

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

int dp[4001][4001];

int main() {
  string s;
  string t;
  int mx;
  
  while( getline(cin, s) ) {
    fill(dp[0], dp[4000] + 4000, 0);
    getline(cin, t);
    int n = s.size(), m = t.size();
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	if( s[i] == t[j] ) {
	  dp[i+1][j+1] = dp[i][j] + 1;
	} else {
	  dp[i+1][j+1] = 0;
	}
      }
    }
    
    mx = 0;
    for(int i=0; i<=n+1; i++)
      for(int j=0; j<=m+1; j++)
	mx = max(mx, dp[i][j]);
    
    cout << mx << endl;
  }
  
  return 0;
}