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] = 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<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int main() {
	string a,b;
	while(cin>>a>>b){
	int sum=0;
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			if(a[i]==b[j]){
				int sum2=0;
				int i2=i,j2=j;
				while(i2<a.length()&&j2<b.length()&&a[i2]==b[j2]){
					sum2++;
					i2++;
					j2++;
				}
				sum=max(sum,sum2);
			}
		}
	}
	cout<<sum<<endl;
}
}

C++: #include <cstdio>
#include <cstring>

int main(void){
  char ra[4005]={0};
  char rb[4005]={0};
  while(scanf("%s%s",ra,rb)!=EOF){
    int alen=strlen(ra);
    int blen=strlen(rb);
    //printf("%d\n%d\n",alen,blen);
    int i=0;
    int j=0;
    int k=0;
    int km=0;
    int ans=0;
    for(i=0;i<alen;i++){
      k=(alen-i<blen)?alen-i:blen;
      km=0;
      for(j=0;j<k;j++){
	if(ra[i+j]==rb[j]){
	  km++;
	}
	else{
	  ans=(ans<km)?km:ans;
	  km=0;
	}
      }
    }
    printf("%d\n",ans);
  }
  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++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string s1, s2;
    while(cin >> s1 >> s2) {
        //vector<vector<int> > dp(s1.size(), vector<int>(s2.size(), 0));
        vector<int> dp[2];
        dp[0].resize(s2.size());
        dp[1].resize(s2.size());
        fill(dp[0].begin(), dp[0].end(), 0);
        fill(dp[1].begin(), dp[1].end(), 0);

        int ans = 0;
        int l1 = s1.size();
        int l2 = s2.size();
        for(int i = 0; i < l1; ++i) {
            int curr = i&1;
            int prev = 1-curr;
            for(int j = 0; j < l2; ++j) {
                if(s1[i] == s2[j]) {
                    if(i > 0 && j > 0) dp[curr][j] = dp[prev][j-1]+1;
                    else dp[curr][j] = 1;
                }
                if(dp[curr][j] > ans) ans = dp[curr][j];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    string str1, str2;
    bool flag;
    while(cin >> str1 >> str2){
        flag = false;
        if(str1.length() > str2.length()){
            string ttt = str1;
            str1 = str2;
            str2 = ttt;
        }
        for(int i = str1.length();i>0;i--){
            for(int j = 0;j<=str1.length()-i;j++){
                string sstr = str1.substr(j, i);
                if(str2.find(sstr) != string::npos){
                    cout << i << endl;
                    flag = true;
                }
                if(flag) break;
            }
            if(flag) break;
        }
        if(!flag) cout << 0 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    string s1,s2;
	int dp[4001][4001];
	for(int i=0;i<=4000;i++){
		dp[i][0]=0;
		dp[0][i]=0;
	}
	while(scanf("%s",s1)!=EOF){
		scanf("%s",s2);
		int ans=0;
		for(int i=1;i<=s1.length();i++){
			for(int j=1;j<=s2.length();j++){
				if(s1[i-1]==s2[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else dp[i][j]=0;
				ans=max(ans,dp[i][j]);
			}
		}
	printf("%d\n",ans);
	}
    return 0;
}

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) {
    vector<vector<int> > dp(2,vector<int>(4005,0));
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[1][j + 1] = dp[0][j] + 1;
	  chmax(maxv,dp[1][j + 1]);
	}else {
	  dp[1][j + 1] = 0;
	}
      }
      dp[0] = dp[1];
    }
    cout << maxv << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int dp[4010][4010];

signed main(){
    string s, t;
    while(cin >> s >> t){
        rep(i, 0, 4010) rep(j, 0, 4010) dp[i][j] = 0;
        int MAX = 0;
        rep(i, 0, s.size()){
            rep(j, 0, t.size()){
                if(s[i] == t[j]){
                    if(i != 0 && j != 0) dp[i][j] = dp[i - 1][j - 1] + 1;
                    else dp[i][j] = 1;
                    MAX = max(MAX, dp[i][j]); 
                }
            }
        }
        cout << MAX << endl;
    }
}

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

int main(){
  int i,j,ans,c;
  int a[2][4001];
  string str,str2;
  while(cin >> str >> str2){
    
    for(i=0;i<=str.size();i++) a[0][i] = 0;
    for(j=0;j<=str2.size();j++) a[0][j] = 0;

    ans = 0;
    for(i=1;i<=str.size();i++){
      for(j=1;j<=str2.size();j++){
	if(str[i-1] == str2[j-1]){
	  a[1][j] = a[0][j-1] + 1;
	  ans = max(ans,a[1][j]);
	}
	else a[1][j] = 0;
      }
      for(j=0;j<str2.size();j++) a[0][j] = a[1][j];
    }

    cout << ans << endl;
    
  }
  return 0;
}

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

using namespace std;

int main()
{
	for(string s1,s2;cin>>s1>>s2;){
		int len1=s1.length(),len2=s2.length();
		int lcslen=0;
		for(int i=-len2+1;i<len2;i++){
			int cnt=0;
			for(int j=0;j<len1;j++){
				if(0<=i+j && i+j<len2 && s1[j]==s2[i+j])	cnt++;
				else	lcslen=max(lcslen,cnt),cnt=0;
			}
			lcslen=max(lcslen,cnt);
		}
		cout<<lcslen<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
string s, t;
int dp[4005][4005], ans;
signed main() {
	while (cin >> s >> t) {
		for (int i = 0; i <= 4000; i++)for (int j = 0; j <= 4000; j++)dp[i][j] = 0;
		ans = 0;
		for (int i = 1; i <= s.size(); i++) {
			for (int j = 1; j <= t.size(); j++) {
				if (s[i - 1] == t[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
					ans = max(dp[i][j], ans);
				}
			}
		}
		cout << ans << endl;
	}
}