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<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    string s1,s2;
	int dp[401][401];
	for(int i=0;i<=400;i++){
		dp[i][0]=0;
		dp[0][i]=0;
	}
	while(EOF){
		int ans=0;
		cin >> s1 >> s2;
		for(int i=1;i<=s1.length();i++){
			for(int j=1;j<=s2.length();j++){
				if(s1[i-1]==s2[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else dp[i][j]=0;
				ans=max(ans,dp[i][j]);
			}
		}
	printf("%d\n",ans);
	}
    return 0;
}

C++: 
//=====================================================
// 
// (setq backup-inhibited t)
// (setq auto-save-default nil)
// 
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
// 
// (global-set-key "\C-h" 'delete-backward-char)
// 
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\C-m" 'newline-and-indent)
// 
//=====================================================

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    string s;
    string t;
    cin >> s;
    cin >> t;
    if(!cin) break;
    set<string> st;
    for (int i = 0; i < s.size(); ++i) {
      for (int j = 0; i + j < s.size(); ++j) {
        st.insert(s.substr(i,j));
      }
    }
    size_t ml = 0;
    for (const string& str : st) {
      if(t.find(str) != string::npos)
        ml = max(ml, str.size());
    }
    cout << ml << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define LL long long 
const int INF = 1145141919;

int dp[4002][4002];

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[4001][4001]={};
char str1[4005],str2[4005];
short ans=0;
int main(){while(scanf("%s%s",str1,str2)!=-1){
  for(int i=0;i<strlen(str1);i++){
    for(int j=0;j<strlen(str2);j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,1);}
         else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}}printf("%d\n",ans); }return 0;}

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

int main(){
    string str,test;
    while(cin>>str>>test){
        vector<string> v;
        int N=str.size();
        for(int i=0;i<N;i++){
            v.push_back( str.substr(i,N-i) );
        }
        sort(v.begin(),v.end());
        int ans=N;
        for(int i=1;i<test.size();i++){
            bool flag=false;
            for(int j=0;j<test.size()-i+1;j++){
                string tmp = test.substr(j,i);
                vector<string>::iterator itr = lower_bound(v.begin(),v.end(),tmp);
                int z=(int)(itr-v.begin());
                if(z!=N && v[z].size() >= i){
                    if(tmp == v[z].substr(0,i)){
                        flag=true;
                        break;
                    }
                }
            }
            if(!flag){
                ans=i-1;
                break;
            }
        }
        cout<<ans<<endl;
        str.clear();
        test.clear();
    }
    
    return 0;
}

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

int main()
{
  string s, t;
  while (cin >> s >> t) {
    short int ans = 0;
    vector<vector<short int> > dp(s.size()+1, vector<short int>(t.size()+1, 0));
    for (unsigned int i = 0; i < s.size(); ++i) {
      for (unsigned int j = 0; j < t.size(); ++j) {
	if (s[i] == t[j]) {
	  dp[i+1][j+1] = dp[i][j]+1;
	  ans = max(ans, dp[i+1][j+1]);
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}