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 <cstdio>
#include <string>
#include <algorithm>
using namespace std;

string s, t;
char tmp[4001];
int dp[4001][4001];

int main(){
	while(1){
		scanf("%s", tmp);
		if(tmp[0] == EOF) break;

		s = tmp;
		scanf("%s", tmp);
		t = tmp;

		for(int i=0; i<4001; i++)
			for(int j=0; j<4001; j++)
				dp[i][j] = 0;

		int ans = 0;
		for(int i=1; i<s.size(); i++){
			for(int j=1; j<t.size(); j++){
				if(s[i-1] == t[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++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)

int main()
{
  string S, W;
  while(cin >> S >> W) {
    int dp[4005] = {0};
    int maxv = 0;
    Rep(i,W.size()) {
      for(int j = S.size(); j > 0; j--) {
	if(S[j - 1] == W[i]) {
	  dp[j] = dp[j - 1] + 1;
	  maxv = max(maxv, dp[j]);
	} else dp[j] = 0;
      }
    }
    cout << maxv << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string a,b;
	while(cin>>a>>b){
		int n=0;
		int la=a.size();
		int lb=b.size();
		for(int i=1-la;i<lb;i++){
			int k=0;
			for(int j=0;j<la;j++){
				if(j+i<0||j+i>lb-1){
					k=0;
				}
				else if(a[j]==b[j+i]){
					k++;
					n=max(n,k);
				}
				else{
					k=0;
				}
			}
		}
		cout<<n<<endl;
	}
    return 0;
}

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

int cnt[4001][4001];

int main(){
	string a, b;
	int na, nb;

	cin >> a >> b;
	na = a.length();
	nb = b.length();

	for(int i=0; i<na+1; i++){
		cnt[i][0] = 0;
	}
	for(int j=0; j<nb+1; j++){
		cnt[0][j] = 0;
	}

	int mx = 0;
	for(int i=0; i<na; i++){
		for(int j=0; j<nb; j++){
			if(a[i]==b[j]){
				cnt[i+1][j+1] = cnt[i][j] + 1;
				if(mx < cnt[i+1][j+1]){
					mx = cnt[i+1][j+1];
				}
			}else{
				cnt[i+1][j+1] = 0;
			}
		}
	}
	cout << mx << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
int dp[4001][4001];
using namespace std;
int main(){
  string s,str;
  int ans = 0;
  while(cin >> s >> str){
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[j]){
          dp[i+1][j+1] = dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  string s, t;
  while (cin >> s >> t) {
    vvi dp(s.size() + 1, vi(t.size() + 1));
    int maxi = 0;
    rep(i, s.size()) rep(j, t.size()) {
      if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
      cmax(maxi, dp[i + 1][j + 1]);
    }
    cout << maxi << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;


int n;
char A[4001],B[4001];

void calc(){
    int an,bn,p,ans=0;
    
    for(an=0;A[an]!='\0';an++);
    for(bn=0;B[bn]!='\0';bn++);
    
    for(int i=0;i<an;i++){
        p=0;
        for(int j=0;j<bn && i+j<an;j++){
            
            if(A[i+j]==B[j]){
                p++;
                ans=max(ans,p);
            }else{
                p=0;
            }
        }
    }
    
    printf("%d\n",ans);
    
    return;
}

int main(){
    string in1,in2;
    
    while(scanf("%s%s",A,B)!=EOF){
        calc();
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
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 VS vector<string>

int main(void) {
    string s,t;
    int max=0;
    while(cin >> s >> t) {
        vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1, 0));
        REP(i,s.size()) {
            REP(j,t.size()) {
                dp[i][j] = -1;
            }
        }
        REP(i,s.size()) {
            dp[i][0] = 0;
        }
        REP(i,t.size()) {
            dp[0][i] = 0;
        }

        FOR(i,1,s.size()+1) {
            FOR(j,1,t.size()+1){
                if(s[i-1] != t[j-1]) dp[i][j] = 0;
                else dp[i][j] = dp[i-1][j-1] + 1;
                max = fmax(max, dp[i][j]);
            }
        }
        cout << max << endl;
        max = 0;
    }
}

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

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

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(cin){
		string s, t; int roop1=0, save=0, 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= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						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;
	}
	
	return 0;
}