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] = 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 <algorithm>
#include <string>
#include <fstream>

using namespace std;

int check(string, string);

int main()
{
  //ifstream ifs("data.txt");
  string str1, str2;
  while( cin >> str1 >> str2 ){

    int res = 0;

    for(int i = 0; i < max(str1.size(), str2.size()); i++){
      if(str1.size() > str2.size())
	rotate(str1.begin(), str1.begin() + 1, str1.end());
      else
	rotate(str2.begin(), str2.begin() + 1, str2.end());

      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
  //ifs.close();
}

int check(string str1, string str2)
{
  int sn = 0, res = 0;
  for(int i = 0; i < min(str1.size(), str2.size()); i++){
    if(str1[i] == str2[i]){
      sn++;
      res = max(res, sn);
    }else{
      sn = 0;
    }
  }
  return res;
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str1;
string str2;
int main(){
	while(cin>>str1>>str2){
		int ans = 0;
		for(int i = 0;i <str1.length();i++){
			for(int j=0;j <str1.length();j++){
				string tmp =str1.substr(i,j);
				if(str2.find(tmp) !=string::npos){
					int k = tmp.length();
					ans =max(ans,k);
				}
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define rep(a,b) for(int a=0;a<b;a++)
#define pb push_back
#define str string
#define INF 100000000
using namespace std;
LL sub_string(const string& s1,const string& s2,LL l1,LL l2){
    LL len=min(s1.length()-l1,s2.length()-l2);
    LL lon=0;
    LL ans=0;
    for(int j=0;j<len;j++){
        if(s1[l1+j]==s2[l2+j]){
            lon++;
        }else{
            ans=max(ans,lon);
        }
    }return max(ans,lon);
}
int main(){
    str s1,s2;
    LL ans=0;
    int i=0;
    while(1){
    cin >> s1 >> s2;
    if(s1=="EOF")break;
    LL l1=s1.length();
    LL l2=0;
        while(l1!=0||l2<=s2.length()){
            if(l1!=0){
                l1--;
            }else{
                l2++;
            }
            ans=max(ans,sub_string(s1,s2,l1,l2));
        }
        cout << ans << endl;
    }
return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s2;
  while(cin >> s >> s2){
    ll ans = 0;
    rep(i,s.size()){
      ll len = 0;
      for(int j = 0; j < s2.size();){
        if(s[i+len] == s2[j+len]){
          len++;
          ans = max(len,ans);
          if(i+len >= s.size() || j+len >= s2.size()) break;
        }
        else{
//           if(len>1){
//             j += len-1;
//           }
//           else{
            ++j;
//           }
          len = 0;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(void){
char str1[4001],str2[4001];
 int i,j,count,len1,len2;
static short dp[4002][4002];

  while(~scanf("%[^\n]%*c",str1)){
    scanf("%[^\n]%*c",str2);

    memset(dp,0,sizeof(dp));

    count=0;

    len1=strlen(str1);
    len2=strlen(str2);

    for(i=0;i<len1;i++){
      for(j=0;j<len2;j++){

	if(str1[i]==str2[j]){
	  dp[i+1][j+1]=dp[i][j]+1;
	  count=count>dp[i+1][j+1]?:dp[i+1][j+1];
	}
	else dp[i+1][j+1]=0;
	
      }
    }
    printf("%d\n",count);
  }

  return 0;
}

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

using namespace std;

int main()
{
	string str,str2;
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		int ans=0;
		if(str.size()>str2.size())
		{
			string a;
			a=str2;
			str2=str;
			str=a;
		}
		
		for(int i=0;i+ans<str.size();i++)
		{
			for(int j=ans+1;i+j<=str.size();j++)
			{
				string se;
				se=str.substr(i,j);
				if(str2.find(se)!=-1)
				{
					if(ans<se.size())
						ans=se.size();
				}
				else
				{
					break ;
				}
			}
		}
		cout << ans << endl;
	}
}