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 <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int check(string, string);

int main()
{
	string s1, s2;

	while(cin >> s1 >> s2)
	{
		int res = 0;
		if(s1.size() < s2.size()) swap(s1, s2);

		for(int i = 0; i < s1.size(); i++)
			res = max(res, check(s1.substr(i, s1.size()), s2));

		for(int i = 0; i < s2.size(); i++)
			res = max(res, check(s2.substr(s2.size()-1-i, s2.size()), s1));

		cout << res << endl;
	}
}

int check(string s1, string s2)
{
	int res = 0, sn = 0;
	for(int i = 0; i < min(s1.size(), s2.size()); i++){
		if(s1[i] == s2[i])	sn++;
		else				sn = 0;

		res = max(res, sn);
	}
	return res;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(1){
	cin >> s >> 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 <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

string str[2];
int dp[4001][4001];

void solve()
{
	
	int ans = 0;


	if(str[0].length() > str[1].length()){
		swap(str[0],str[1]);
	}
	for(int i = 0; i < 4001; i++){
		for(int j = 0; j < 4001; j++)
			dp[j][i] = 0;
	}
	for(int i = 0; i < str[0].length(); i++){
		for(int j = 0; j < str[1].length(); j++){
			if(str[0][i] == str[1][j]){
				dp[j+1][i+1] += (dp[j][i]+1);
				ans = max(ans,dp[j+1][i+1]);
			}


		}
	}
	
/*
// dp表 確認(日本語)
// dp-table checking(English)

	cout << " ";
	for(int i = 0; i < str[0].length(); i++)
		cout << "  " << str[0][i];
	cout << endl;

	for(int i = 0; i < str[1].length(); i++){
		cout << str[1][i];
		for(int j = 0; j < str[0].length(); j++)
			printf("%3d", dp[i][j]);
		cout << endl;
	}
*/
	cout << ans << endl;

			
	
}


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

	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<int> > dp(T.size() + 1, vector<int>(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; }

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

				if (T[i] == S[j])
				{
					dp[i][j]++;
				}
			}
		}

		printf("%d\n", dp[T.size()][S.size()]);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(cin.eof()){
	cin >> s >> t;
	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++;
							cout << save[roop2] << ' ';
						}
						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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char str1[4001], str2[4001];
int main() {
    while (scanf("%s%s",&str1,&str2)!=EOF) {
        int res=0;
        for (int off=-1*(int)strlen(str1); off<=(int)strlen(str2); off++) {
            int len=0;
            for (int i=max(off,0); i<min(strlen(str1)+off,strlen(str2)); i++) {
                if (str1[i-off]==str2[i]) {
                    len++;
                    res=max(res,len);
                } else {
                    len=0;
                }
            }
        }
        printf("%d\n",res);
    }
}

C++: #include<bits/stdc++.h>
#define lld long long int
#define str string


using namespace std;

lld f();
lld ster,leg,leg2,ans=0,ans2=0;

str moji,moji2,cut;

int main(){

    cin >> moji >> moji2;
    leg=moji.size();
    leg2=moji2.size();

    cout << f() << endl;

return 0;
}

lld f(){
    for(int a=0;a<leg;a++){
            for(int b=1;b<leg-a;b++){
        cut = moji.substr(a,b);
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    }
    return ans2;
}

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

using namespace std;

void solve()
{
	string str1, str2;
	while(cin >> str1 >> str2)
	{
		int length1 = str1.size();
		int length2 = str2.size();
		int max = 0;
		for(int i = 0; i < length1; ++i)
		{
			int count = 0;
			for(int j = 0; j < length2; ++j)
			{
				int pos1 = i;
				int pos2 = j;
				while(str1[pos1] == str2[pos2])
				{
					if((pos1 == length1 - 1) || (pos2 == length2 - 1))
					{
						break;
					}
					++pos1;
					++pos2;
					count++;
					if(max < count)
					{
						max = count;
					}
				}
				count = 0;
			}
		}
		cout << max << endl;
	}
}

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

C++: #include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


string X, Y;
int dp[4001][4001], m;

int main(void) {
  while(1) {
    cin >> X >> Y;
    if(cin.eof()) break;

    m = 0;

    REP(i, 0, X.length()) dp[i][0] = 0;
    REP(j, 0, Y.length()) dp[0][j] = 0;

    REP(i, 1, X.length() + 1) {
      REP(j, 1, Y.length() + 1) {
        dp[i][j] = X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1 : 0;
        m = max(m, dp[i][j]);
      }
    }

    cout << m << endl;
  }

  return 0;
}