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 <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 <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){

	string str[2];
	while(cin >> str[0] >> str[1]){
		int maxLength = 0;
		for(int i = 0; i < str[0].size(); i++){
			for(int j = 0; j < str[1].size(); j++){
				if(str[0][i] == str[1][j]){
					int length = 1;
					for(int k = 1; k + i < str[0].size() && k + j < str[1].size(); k++){
						if(str[0][k+i] == str[1][k+j])
							length++;
						else
							break;
					}
					maxLength = max(maxLength,length);
				}
			}
		}
		cout << maxLength << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
char a[4001];
char b[4001];
int dp[4001][4001];
int max(int a,int b){return a>b?a:b;}
int main(){
	while(scanf(" %s",a)!=EOF){
	scanf(" %s",b);
	int n=strlen(a);
	int m=strlen(b);
	int i,j;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)dp[i][j]=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(a[i]==b[j])dp[i+1][j+1]=dp[i][j]+1;
		}
	}
	int ans=0;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)ans=max(ans,dp[i][j]);
	printf("%d\n",ans);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	char str1[1<<12],str2[1<<12];
	int dp[1<<12][1<<12];
	int memo[1<<13];
	while(cin>>str1>>str2){
		memset(memo,0,sizeof(memo));
		memset(dp,0,sizeof(dp));
		int n = strlen(str1);
		int m = strlen(str2);
		int ans = 0;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				int t = i-j>=0 ? i-j : n+m+i-j;
				if( str1[i-1]==str2[j-1] ){
					memo[t]++;
				}else{
					memo[t]=0;
				}
				dp[i][j] = max(memo[t],dp[i-1][j-1]);
				ans = max(ans,dp[i][j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x);

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

char str1[4010];
char str2[4010];

int main(){
  while(~scanf("%s %s",str1,str2)){
    int ans = 0;
    int len1 = strlen(str1);
    int len2 = strlen(str2);

    for(int i=0; i+ans < len1; i++){
      for(int j=0; j+ans < len2; j++){
        if(str1[i] == str2[j]){
          int tmp = 0;
          int ii = i;
          int jj = j;
          while(str1[ii] && str1[ii++] == str2[jj++])
            ++tmp;
          ans = max(ans, tmp);
        }
      }
    }
    print(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;
  int dp[4005] = {0};
  int maxv = 0;
  
  while(cin >> S) {
    cin >> W;
    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 <cstring>
using namespace std;

int dp[4002][4002];

int main(){
  string a, b;

  while(cin >> a >> b){
    int n = a.length();
    int m = b.length();

    memset(dp, 0, sizeof(dp));
    int res = 0;

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= m; j++){
        if(a[i - 1] == b[j - 1]){
          dp[i][j] = dp[i - 1][j - 1] + 1;
          res = max(res, dp[i][j]);
        }
      }
    }

    cout << res << endl;
  }
}

C++: #include<cstdio>
#include<cstring>
#define max(a,b) (a>b?a:b)
char a[4000],b[4000];
int table[4001],n=0;
int main(){
	while(~scanf("%s%s",a,b)){
	memset(table,0,sizeof(table));
	for(int i=1;i<=strlen(a);i++){
		for(int j=strlen(b);j;j--){
			if(a[i-1]==b[j-1])
				table[j]=max(table[j],table[j-1]+1);
			n=max(n,table[j]);
		}
	}
	printf("%d\n",n);
	}
	return 0;
}

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

using namespace std;

int main()
{
    string instr1,instr2;
    cin >> instr1 >> instr2;

    while(!cin.eof()) {
        vector<vector<int> > dp;

        dp.resize(instr1.size());

        int ans=0;

        for(int i=0; i<(int)instr1.size(); ++i) {
            dp[i].resize(instr2.size());

            if(instr1[i]==instr2[0]) {
                dp[i][0]=1;
                ans=1;
            } else {
                dp[i][0]=0;
            }
        }

        for(int i=0; i<(int)instr2.size(); ++i) {
            if(instr1[0]==instr2[i]) {
                dp[0][i]=1;
                ans=1;
            } else {
                dp[0][i]=0;
            }
        }


        for(int i=1; i<(int)instr1.size(); ++i) {
            for(int j=1; j<(int)instr2.size(); ++j) {
                if(instr1[i]==instr2[j]) {
                    dp[i][j]=dp[i-1][j-1]+1;
                    ans=max(dp[i][j],ans);
                }
            }
        }

        cout << ans << endl;

        cin >> instr1 >> instr2;
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  string a,b;
  while(cin >> a >> b){
    int ans = 0;
    for(int i = 0; i < (int)a.size(); i++){
      int c = 0;
      int t = 0;
      for(int j = 0; j < (int)a.size() - i && j < (int)b.size(); j++){
	if(a[i+j] == b[j]){
	  c++;
	}else{
	  t = max(t,c);
	  c = 0;
	}
      }
      ans = max(max(t,c),ans);
     for(int j = 0; j < (int)a.size() && j < (int)b.size() - i; j++){
	if(a[j] == b[i+j]){
	  c++;
	}else{
	  t = max(t,c);
	  c = 0;
	}
      }
      ans = max(max(t,c),ans);
    }
    cout << ans << endl;
  }
}