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>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s, t;
int dp[5000][5000];

int main(){
	while (cin >> s >> t){
		REP(i, 5000)REP(j, 5000)dp[i][j] = 0;
		int ans = -1;
		REP(i, s.size()){
			REP(j, t.size()){
				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;
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 4002
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(scanf("%s",&s)){
  ZERO(dp);
  scanf("%s",&t);
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d",ma);
 }
}

int main(){
 solve();
 return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int sln,tln,mx;
  string s,t;
  while(cin>>s){
    cin>>t;
    sln=s.length();
    mx=0;
    for(i=0;i<sln-mx+1;i++){
      for(j=mx+1;j<sln-i+1;j++){
	if(t.find(s.substr(i,j))!=string::npos)
	  mx=j;
	else
	  break;
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

int main(void){
	char str1[4001]={0},str2[4001]={0};
	str1[0]='0';
	str2[0]='0';
	
	while(scanf("%s",&str1[1])!=EOF){
		int dp[2][4002]={0};
		int i,j,st1,st2,max=0,f=0;
		
		scanf("%s",&str2[1]);
		
		st1=strlen(str1);
		st2=strlen(str2);
		
		for(i=1;i<st1;i++){
			for(j=1;j<st2;j++){
				if(str1[i]==str2[j]){
					dp[f][j]=dp[1-f][j-1]+1;
				}
				else dp[f][j]=0;
				
				if(dp[f][j]>max)max=dp[f][j];
			}
			if(f)f=0;
			else f=1;
		}
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include "stdio.h"
#include "string.h"

char st1[5000];
char st2[5000];
char flg[5000];
int ans[1000];

int main()
{
  int nw = 0;
  while(1)
    {
      char w;
      w = getchar();
      if(w == EOF)
	{
	  break;
	}
      scanf("%s",st1);
      scanf("%s",st2);
      int st1l,st2l;
      st1l = strlen(st1) - 1;
      st2l = strlen(st2) - 1;
      int m = 0;
      for(int i = 0; i < st1l; i++)
	{
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      flg[ii] = 0;
	    }
	  for(int ii = i; ii < st1l; ii++)
	    {
	      flg[ii] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      flg[ii] = flg[ii] - st2[ii];
	    }
	  int n = 0;
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;

int main(){
	string s, t;
	while(cin>>s>>t){
		if(s.size()>t.size()) swap(s,t);
		int ans = 0;
		for(int i = 0; i < s.size(); i++){
			for(int j = 1; j < s.size() - i; j++){
				if(t.find(s.substr(i, j))!=string::npos){
					ans = max(ans,j);
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    string n, m;
    while(cin >> n >> m){
        int ans = 0;
        if(n.size() > m.size()) swap(n, m);
        for(int i=0; i < n.size(); i++){
            for(int j=i+1; j <= n.size(); j++){
                if(j-i <= ans) continue;
                string s = n.substr(i, j-i);
                if(m.find(s) != string::npos){ans = max(ans, (int)s.size());}
                else j = 40000;
            }
        }
        cout << ans << endl;
    }
}

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

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++;
    else{
      res = max(res, sn);
      sn = 0;
    }
  }
  return res;
}