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 <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int common(const string &a, const string &b){
	int size = min(a.size(), b.size());
	int res = 0, cnt = 0;
	rep(i, size){
		if(a[i]==b[i]) cnt++;
		else{
			res = max(res, cnt);
			cnt = 0;
		}
	}
	return max(res, cnt);
}

int check(const string &a, const string &b){
	int res = 0;
	rep(i, a.size()){
		res = max(res, common(a.substr(i), b));
	}
	return res;
}

int main(){
	string a, b;
	while(cin >> a >> b){
		cout << max(check(a, b), check(b, a)) << endl;
	}


    return 0;
}

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

using namespace std;

string in[2];

void solve()
{
	int res = 0;
	for(int u = 0; u < 2; u++){
		for(int i = 0; i < in[0].length(); i++){
			for(int j = 0; j < in[1].length(); j++){
				if(in[0][i] == in[1][j]){
					int row = 1;
					for(int k = 1; i+k < in[0].length() && j+k < in[1].length(); k++,row++){
						if(in[0][i+k] != in[1][j+k])
							break;
					}
					res = max(res,row);
				}
			}
		}
		swap(in[0],in[1]);

	}

	cout << res << endl;
}

int main(void)
{
	while(cin >> in[0] >> in[1], !cin.eof())
		solve();

	return 0;
}

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

using namespace std;
int len[4001][4001];

int main(void){
	int a,b;
	while(1){
		memset(len,0,sizeof(len));
		string str;
		string str2;
		cin >> str;
		if(str=="EOF")break;
		cin >> str2;
		for(a=0;a<str.size();a++){
			for(b=0;b<str2.size();b++){
				if(str[a]==str2[b]){
					len[a+1][b+1]=len[a][b]+1;
				}else{
					len[a+1][b+1]=max(len[a+1][b],len[a][b+1]);
				}
			}
		}
		cout << len[a][b] << endl;
	}
	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);
      st2l = strlen(st2);
      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>
using namespace std;

int main(){
	string s,t;
	static int dp[4001][4001] = {};
	while(cin >> s >> t){
		for(int i = 0;i <= s.length();i++){
			for(int j = 0;j <= t.length();j++) dp[i][j] = 0;
		}
		int ma = 0;
		for(int i = 0;i < s.length();i++){
			for(int j = 0;j < t.length();j++){
				if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
				ma = max(ma,dp[i + 1][j + 1]);
			}
		}
		cout << ma << endl;
	}
	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, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s==""){
		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;
}

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,roop3, save[50000]={}, 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 range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int MAX_N = 4005;
int dp[MAX_N + 1][MAX_N + 1];
string s, t;

int solve(){
    int n = s.size(), m = t.size(); //????????°?????±?????¨?????????????????????
    rep(i,MAX_N) rep(j,MAX_N) dp[i][j] = 0;

    rep(i,n){
        rep(j,m){
            if(s[i] == t[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            //jelse{
            //j    dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j]);
            //j}
        }
    }

    int sum = 0;
    rep(i,n + 1){
        rep(j,m + 1){
            sum = max(sum,dp[i][j]);
        }
    }
    return sum;
}

int main(){
    while(cin >> s >> t){
        cout << solve() << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  string s, t;
  while(cin >> s >> t) {
    int dp[4005][4005] = {0};
    int ss = s.size(), ts = t.size();

    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	}
      }
    }

    cout << *max_element(dp[0],dp[ts]) << endl;
  }
  return 0;
}