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++: //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 = 0, save[65000]={}, ans = 0;
		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>
using namespace std;
int main(){
  string str,str2;
  while( cin >> str){
    cin >> str2;
    int ans = 0;
    for(int i = 0 ; i < str.size()-1 ; i++){
      for(int j = 1 ; i+j < str.size() ; j++){
	if(str2.find(str.substr(i,j)) != string::npos ){
	  ans = max(ans,j);
	}
      }
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int memo[4040][4040] = {};
int main(void){
	string s, t;
	while(cin >> s && s.size()){
		int res = 0;
		cin >> t;
		memset(memo, 0, sizeof memo);
		REP(i, s.size()){
			REP(j, t.size()){
				if(memo[i][j] != 0) continue;
				int cnt = 0;
				if(s[i] == t[j]){
					cnt++;
					memo[i][j] = cnt;
					while(s[i+cnt] == t[j+cnt] && i+cnt < s.size() && j+cnt < t.size()){
						cnt++;
						memo[i+cnt][j+cnt] = cnt;
					}
					res = max(res, cnt);
				}
			}
		}
		cout << res << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	string s,t;
	while(cin>>s>>t){
		int n = s.size(), m = t.size();
		int ans = 0;
		REP(i,n){
			int cnt = 0;
			for(int j = 0; j < m && i + j < n; j++){
				if(s[i+j] == t[j])cnt++;
				else cnt=0;
				ans = max(ans,cnt);
			}
		}
		swap(s,t); n = s.size(); m = t.size();
		REP(i,n){
			int cnt = 0;
			for(int j = 0; j < m && i + j < n; j++){
				if(s[i+j] == t[j])cnt++;
				else cnt=0;
				ans = max(ans,cnt);
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    string a;
    while(cin >> a) {
        string b;
        cin >> b;
        int ans = 0;
        rep (va, 2) {
            string & s = va ? a : b,
                   & t = va ? b : a;

            for (int i = s.size() - 1; i >= 0; i--) {
                string tmp = "";
                range (j, i, s.size()) tmp += s[j];
                int cnt = 0;
                rep (j, tmp.size()) {
                    if (tmp[j] == t[j]) {
                        cnt++;
                        ans = max(ans, cnt);
                    }
                    else {
                        cnt = 0;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	while(cin>>s>>t){
		int roop1=0, save=0, ans = 0;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save= 0;
				while (1){
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
}

C++: #include <bits/stdc++.h>
std::map<std::string,int>mp;
int main(){
    std::string s;
    std::string b;
    
    while(std::cin>>s){
        std::cin>>b;
        mp.clear();
        if(b.size()>s.size())std::swap(s,b);
        for(int i=0;i<s.size();i++){
            for(int j=i+1; j<s.size();j++){
                std::string temp=s.substr(i,j-i);
                mp[temp]=1;
            }
        }
        int ans=0;
        for(int i=0;i<b.size();i++){
            for(int j=i+1; j<b.size();j++){
                std::string comp=b.substr(i,j-i);
                if(mp[comp])ans=std::max(ans,(int)comp.size());
            }
        }
        std::cout<<ans<<std::endl;
    }
}

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

main() {
  while(1) {
    char str[2][4001];
    int state;
    state = scanf("%s\n", str[0]);
    if(state == EOF) break;
    scanf("%s\n", str[1]);

    int data[strlen(str[0])+10][strlen(str[1])+10];
    int maxL = 0;
    for(int i = 0; i <= strlen(str[0]); i++) {data[i][0] = 0;}
    for(int j = 0; j <= strlen(str[1]); j++) {data[0][j] = 0;}

    for(int i = 1; i <= strlen(str[0]); i++) {
      for(int j = 1; j <= strlen(str[1]); j++) {
	if(str[0][i-1] == str[1][j-1]) data[i][j] = data[i-1][j-1]+1;
	else     data[i][j] = 0;

	if(data[i][j] > maxL) maxL = data[i][j];
      }
    }
    cout << maxL << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

int dp[4040][4040];

int main()
{
  string a, b;
  while (cin >> a >> b){
    memset(dp, 0, sizeof(dp));

    int max_n = 0;
    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        if (i * j == 0){
          dp[i][j] = a[i] == b[j];
          continue;
        }
        if (a[i] == b[j]) dp[i][j] = 1 + dp[i - 1][j - 1];
      }
    }

    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        max_n = max(max_n, dp[i][j]);
      }
    }

    cout << max_n << endl;
  }
}