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] = 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 <iostream>

using namespace std;

int main() {
  for (;;) {
    string a, b;
    if (!(cin >> a)) return 0;
    cin >> b;
    int result = 0, dp[4001];
    fill(dp, dp+b.length()+1, 0);
    for (int i = 0; i < a.length(); i++)
      for (int j = b.length()-1; j >= 0; j--)
        if (a[i] == b[j]) {
          dp[j+1] = dp[j] + 1;
          if (dp[j+1] > result)
            result = dp[j+1];
        } else dp[j+1] = 0;
    cout << result << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    while(true){
        string s1, s2;
        cin >> s1 >> s2;
        if(s1=="") break;
        int l1=s1.length();
        int l2=s2.length();
        int dp[4010][4010];
        for(int i=0; i<l1; i++){
            if(s1[i]==s2[0]) dp[i][0]=1;
            else dp[i][0]=0;
        }
        for(int j=0; j<l2; j++){
            if(s1[0]==s2[j]) dp[0][j]=1;
            else dp[0][j]=0;
        }
        for(int i=1; i<l1; i++){
            for(int j=1; j<l2; j++){
                if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=0;
            }
        }
        int ans=0;
        for(int i=0; i<l1; i++){
            for(int j=0; j<l2; j++){
                ans=max(ans, dp[i][j]);
            }
        }
        cout << ans << "\n";
        
    }
    
    
    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; }

		int ret = 0;

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

				if (T[i - 1] == S[j - 1])
				{
					dp[i][j]++;
				}
				else
				{
					dp[i][j] = 0;
				}

				ret = max(ret, (int)(dp[i][j]));
			}
		}

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

	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 <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;

#define rep(i, n)      for (int i=0; i<int(n); i++)
#define rep3(i, s, n)  for (int i=int(s); i<int(n); i++)
#define rev_rep(i, n)  for (int i=int(n)-1; i>=0; i-=1)

string s;
string t;
int dp[4010][4010];
int main() {
  while (cin >> s >> t) {
  int s_len = s.length(), t_len = t.length();
  rep(i, s_len) {
    rep(j, t_len) {
      if (s[i] == t[j]) dp[i][j] = ((i>1&&j>1) ? dp[i-1][j-1] : 0) + 1;
      else              dp[i][j] = 0;
    }
  }
  int ans = 0;
  rep(i, s_len) {
    rep (j, t_len) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
  }
  return 0;
}

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

int dp[4002][4002];

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

C++: #include<iostream>
 
using namespace std;
 
int solve(const string& s1, const string& s2, int l1, int l2){
  int tmp = 0;
  int res = 0;
  int len = min(s2.length()-l2,s1.length()-l1);
  for(int i = 0; i < len; i++){
    if(s1[l1+i] != s2[l2+i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}
 
int main(){
   
  string s1,s2;
  int l1,l2,ans;
  while(1) {
  	if(cin.eof()) {
  		break;
  	}
  	cin >> s1;
  	cin >> s2;
  	l1 = s1.length();
  	l2 = 0;
  	ans = 0;
  	while(l1 != 0 || l2 <= s2.length()) {

      if(l1 != 0){
      	l1--;
      } else {
      	l2++;
      }
      ans = max(ans,solve(s1,s2,l1,l2));
  	}
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main()
{
	char a[4001],b[4001];
	while(scanf("%s%s",a,b)>0)
	{
		static int x[4001][4001]={0},i,j,s,t,r;
		s=strlen(a),t=strlen(b);
		for(r=j=0;j<=t;++j)x[0][j]=0;
		for(i=0;i<=s;++i)x[i][0]=0;
		for(i=0;i<s;++i)for(j=0;j<t;++j)if(a[i]==b[j])r=(r>(x[i+1][j+1]=x[i][j]+1)?r:x[i+1][j+1]);
		printf("%d\n",r);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[4001][4001];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        string S, T;
        cin >> S >> T;

        rep(i, S.length()) {
            rep(j, T.length()) {
                if (S[i] == T[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
                //else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                else dp[i + 1][j + 1] = dp[i][j + 1];
            }
        }
        /*
        rep(i, S.length() + 1) {rep(j, T.length() + 1)
            cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        */
        /*
        rep(i, S.length() + 1) {
            cout << i << " ";
            rep(j, T.length() + 1) {
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }
        */
           

        cout << dp[S.length()][T.length()] << endl;
    }


    return 0;
}