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

main() {
  while(1) {
    string str[2];
    getline(cin, str[0]);
    getline(cin, str[1]);
    if(cin.eof()) break;

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

    for(int i = 1; i <= str[0].length(); i++) {
      for(int j = 1; j <= str[1].length(); 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 <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

int count(string& a, string& b) {
    int a_len = a.length();
    int b_len = b.length();
    if (a_len < b_len) {
        swap(a, b);
        swap(a_len, b_len);
    }
    int max_lcs = 0;
    int cur_lcs = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len && i + j < a_len; j++) {
            if (a[i+j] == b[j]) {
                cur_lcs++;
            } else {
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }
    return max_lcs;
}

int main() {
    string a, b;
    while (cin >> a >> b) {
        cout << count(a, b) << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
int d[4044][4044] = {};
int main()
{
        char r[2][4002] = {};
        while (gets (r[0])) {
                gets (r[1]);
memset (d, 0, sizeof d);
                int le, ri, a = 0;
                le = strlen (r[0]), ri = strlen (r[1]);
                for (int i=1; i<=le; i++) {
                        for (int j=1; j<=ri; j++) {
                                if (r[0][i-1] == r[1][j-1]) d[i][j] = d[i-1][j-1] + 1;
                                else d[i][j] = 0;
                                a = a>d[i][j] ? a:d[i][j];
                        }
                }
                printf ("%d\n", a);
        }
        return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  string a,b;
  int c,d;
  int dp[2][5000],ans;
  while(cin>>a>>b){
    c=a.size(),d=b.size();
    ans=0;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=c;i++){
      for(int j=1;j<=d;j++){
	int ni=i%2,ri=1-i%2;
	//niは今のaの文字数が奇数か偶数か dpテーブルの使い回しのため
	//riはniじゃない方←前の結果のdpテーブル
	cout<<a[i-1]<<" "<<b[j-1]<<endl;
	if(a[i-1]==b[j-1]){//一致したら前の状態の前の文字のdpテーブルから値を引っ張ってくる
	  dp[ni][j]=dp[ri][j-1]+1;
	}
	else dp[ni][j]=0;//違うなら打ち切る
	ans=max(ans,dp[ni][j]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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


int main(){
  while(true){
    char s[4001],t[4001];
    int l,r,ans = 0;
    static int dp[4001][4001];
    if(scanf("%s %s",s,t)==EOF) return 0;
    l = strlen(s), r = strlen(t);
    for(int i=0;i<=l;i++){
      for(int j=0;j<=r;j++){
        if(i==0||j==0) dp[i][j] = 0;
        else if(s[i-1]==t[j-1]){
          dp[i][j] = dp[i-1][j-1] + 1;
          ans = max(ans,dp[i][j]);
        }else{
          dp[i][j] = 0;
        }
      }
    }
    printf("%d\n",ans);
  }
}

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

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

int main()
{
  int nw = 0;
  while(1)
    {
      if(NULL == gets(st1))
	{
	  break;
	}
      gets(st2);
      int st1l,st2l;
      st1l = strlen(st1);
      st2l = strlen(st2);
      int m = 0;
      for(int i = 0; i < st1l + st2l; i++)
	{
	  for(int ii = 0; ii < 15000; ii++)
	    {
	      flg[ii] = 1;
	    }
	  for(int ii = 0; ii < st1l; ii++)
	    {
	      flg[ii + st2l] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      if(flg[i + ii] == st2[ii])
		{
		  flg[i + ii] = 0;
		}
	      else
		{
		  flg[i + ii] = 1;
		}
	    }
	  int n = 0;
	  for(int ii = 0; ii < 15000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
      nw++;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}

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[600500000]={}, 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 "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	while (cin >> s) {
		cin >> t;
		int n = s.size(), m = t.size();
		vvi table(n, vi(m, 0));
		REP(i, n) {
			if (s[i] == t[0])table[i][0] = 1;
		}
		REP(i, m) {
			if (s[0] == t[i])table[0][i] = 1;
		}
		REP(i, n - 1) {
			REP(j, m - 1) {
				if (s[i + 1] == t[j + 1])table[i + 1][j + 1] = table[i][j] + 1;
				else table[i + 1][j + 1] = 0;
			}
		}
		int ans = -INF;
		REP(i, n) {
			REP(j, m) {
				ans = max(ans, table[i][j]);
			}
		}
		cout << ans << endl;

	}
	return 0;
}