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

int dp[4000][4000];

int count(string& a, string& b) {
    memset(dp, 0, sizeof(dp));
    int a_len = a.length();
    int b_len = b.length();
    dp[0][0] = 0;
    for (int i = 1; i < a_len; i++) dp[i][0] = 0;
    for (int j = 1; j < b_len; j++) dp[0][j] = 0;
    for (int i = 1; i < a_len; i++) {
        for (int j = 1; j < b_len; j++) {
            if (a[i] == b[j]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    int lcs_len = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len; j++) {
            if (dp[i][j] > lcs_len) {
                lcs_len = dp[i][j];
            }
        }
    }
    return lcs_len;
}

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

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

int dp[4010][4010];

int main(){
	string in1,in2;
	while(cin>>in1>>in2){
		int n = in1.size();
		int m = in2.size();
		int ret = 0;
		rep(i,n+1)rep(j,m+1)dp[i][j]=0;
		REP(i,1,n+1){
			REP(j,1,m+1){
				if( in1[i-1]==in2[j-1] ){
					dp[i][j] = dp[i-1][j-1] + 1;
					ret = max(ret,dp[i][j]);
				}
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<short> > dp(T.size() + 1, vector<short>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		int ret = 0;

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				if (T[i - 1] == S[j - 1])
				{
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else
				{
					dp[i][j] = 0;
				}

				ret = max(ret, (int)(dp[i][j]));
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	while(cin>>s>>t){
		int roop1=0, save=0, ans = 0;
	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] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
}

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

char A[4002],B[4002];

//BのN番目の文字がA中の複数の文字と同じになることがある
int seach(int atop,int lenA,int lenB){
	int i,count,max = 0;
	int acor;
	for(i = 0;i < lenB && max < lenA-atop;){
		acor = 0;
		count = 0;
		for(;i < lenB && count < lenA-atop;i++){
			if(A[acor+atop] == B[i]){
				count++;
				acor++;
			}
			else{
				i += 1-count;
				break;
			}
		}
		if(max < count)
			max = count;
	}
	return max;
}
int main(){
	int i,j,lenA,lenB,kyotu;
	int max[1000] = {0},mcor = 0;
	while(1){
		if(scanf("%s%s",A,B) == -1){
			break;
		}
		lenA = strlen(A);
		lenB = strlen(B);
		for(i = 0;i < lenA;i++){
			kyotu = seach(i,lenA,lenB);
			printf("kyotu = %d\n",kyotu);
			if(max[mcor] < kyotu)
				max[mcor] = kyotu;
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int dp[4001][4001];

int main(void){
	string s1, s2; cin >> s1 >> s2;
	int s1size = s1.size(), s2size = s2.size();
	rep(i, 4001) dp[i][0] = dp[0][i] = 0;

	int ans = 0;
	reps(i, 1, s1size + 1){
		reps(j, 1, s2size + 1){
			if(s1[i] == s2[j]){
				dp[i][j] = max(dp[i - 1][j - 1] + 1, max(dp[i - 1][j], dp[i][j - 1]));
			}else{
				dp[i][j] = max(dp[i - 1][j - 1], max(dp[i - 1][j], dp[i][j - 1]));
			}
			ans = max(ans, dp[i][j]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	string a, b;
	while (cin >> a >> b) {
		int dp[4001][4001];
		for (int i = 0; i < 4001; ++i) {
			for (int j = 0; j < 4001; ++j) {
				dp[i][j] = -1e9;
			}
		}
		dp[0][0] = 0;
		int ans = 0;
		for (int i = 0; i < a.size(); ++i) {
			for (int j = 0; j < a.size(); ++j) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
					else {
						dp[i][j] = 1;
					}

				}
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

char A[4002],B[4002];
short int length[4000][4000];
int mmax[200],mcor = 0;
int main(){
	int i,j,lenA,lenB;
	while(scanf("%s",A) != EOF){
		cin >> B;
		lenA = strlen(A)-1;
		lenB = strlen(B)-1;
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				length[i][j] = -1;
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(length[i][j] >= 0)continue;
				for(int k = 0;i+k < lenA && i+k < lenB;k++){
						if(A[i+k] != B[i+k]){
							length[i][j] = k;
							break;
						}
				}
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(mmax[mcor] < length[i][j])
					mmax[mcor] = length[i][j];
			}
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		cout << mmax[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int ans,cnt;
  string s,t;
  while(cin>>s>>t){
    ans=0;
    for(int i=0;i<s.size();i++){
      string ss=s.substr(i,s.size()-i);
      cnt=0;
      for(int j=0;j<ss.size();j++){
	if(ss[j]==t[j]){
	  cnt++;
	}else{
	  ans=max(ans,cnt);
	  cnt=0;
	}
      }
    }
    for(int i=0;i<t.size();i++){
      string tt=t.substr(i,s.size()-i);
      cnt=0;
      for(int j=0;j<tt.size();j++){
	if(tt[j]==s[j]){
	  cnt++;
	}else{
	  ans=max(ans,cnt);
	  cnt=0;
	}
      }
    }
    cout<<ans<<endl;
  }
}