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++: //JOI 0528 Common Sub-String
#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] == 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());

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

std::string s1,s2;

int dp[4001][4001];

int main() {
    
    while(std::cin>>s1>>s2) {
        
        std::memset(dp,0,sizeof(dp));
        
        for(int i=1;i<=s1.size();++i){
            for(int j=1;j<=s2.size();++j){
                if(s1[i-1]==s2[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
            }
        }
        
        int ans=0;
        
        for(int i=1;i<=s1.size();++i){
            for(int j=1;j<=s2.size();++j){
                ans=std::max(ans,dp[i][j]);
            }
        }
        
        std::cout<<ans<<std::endl;
    }
    
    return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (string s, t; scan(s, t);) {
		vector<vector<int>> d(s.size() + 1, vector<int>(t.size() + 1));
		int l {};
		for (int i: range(1, s.size() + 1))
			for (int j: range(1, t.size() + 1))
				l = max(l, d[i][j] = s[i - 1] == t[j - 1] ? d[i - 1][j - 1] + 1: 0);
		outl(l);
	}
}

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[1000000]={}, 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 <stdio.h>
#include <string.h>

int main(void){
	char str1[4001]={0},str2[4001]={0};
	str1[0]='0';
	str2[0]='0';
	
	while(scanf("%s",str1+1)!=EOF){
		int dp[2][4002]={0};
		int i,j,st1,st2,max=0,f=0;
		
		scanf("%s",str2+1);
		if(str1[1]=='0')break;
		
		st1=strlen(str1);
		st2=strlen(str2);
		
		for(i=1;i<st1;i++){
			for(j=1;j<st2;j++){
				if(str1[i]==str2[j]){
					dp[f][j]=dp[1-f][j-1]+1;
				}
				else dp[f][j]=0;
				
				if(dp[f][j]>max)max=dp[f][j];
			}
			if(f)f=0;
			else f=1;
		}
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int DpLen[4000][4000];

int main() {
	int sLen, tLen, maxLen;
	string s, t;

	while (cin >> s >> t) {
		memset(DpLen, 0, sizeof(DpLen));
		sLen = s.size();
		tLen = t.size();
		maxLen = 0;
		for (int i = 0; i < sLen; ++i) {
			for (int j = 0; j < tLen; ++j) {
				if (s[i] != t[j]) {
					continue;
				}
				if (i == 0 || j == 0) {
					DpLen[i][j] = 1;
				}
				else {
					DpLen[i][j] = DpLen[i - 1][j - 1] + 1;
				}
				maxLen = max(maxLen, DpLen[i][j]);
			}
		}
		cout << maxLen << endl;
	}

	return 0;
}