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>
using namespace std;
char a[20000];
int main(){
	string c,d;
	while(cin>>c>>d){
	for(int i=0;i<20000;i++)
		a[i]='-';
	for(int i=0;i<c.size();i++)
		a[i+10000]=c[i];
	int ans=0;
	for(int first=0;first<20000-d.size();first++){
		int count=0;
		for(int j=0;j<d.size();j++){
			if(a[first+j]==d[j])
				count++;
			else{
				ans=max(ans,count);
				count=0;
			}
		}
		ans=max(ans,count);
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }


int dp[4001][4001];
int main(void){
    char s[4001],t[4001];
//  printf("%d\n",4000*4000);
    while(scanf("%s",s)!=EOF){
        scanf("%s",t);
//      dp[0][0]=s[0]==t[0];
        for(int i=0;i<4001;i++)dp[i][0]=dp[0][i]=0;
        int sl = strlen(s),tl = strlen(t);
        int ans = 0;
        for(int i=1;i<=sl;i++){
            for(int j=1;j<=tl;j++){
                if(s[i-1]==t[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                    ans = max(ans,dp[i][j]);
                }else dp[i][j]=0;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string a,b;
  while(cin>>a>>b){
    vector<vector<int> >dp(a.size()+1,vector<int>(b.size()+1));
    rep(i,a.size())rep(j,b.size()){
      //dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
      if(a[i]==b[j])dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
      
    }
    //cout<<" "<<b<<endl;
    //rep(i,a.size()){cout<<a[i];rep(j,b.size())cout<<dp[i+1][j+1];cout<<endl;}
    //cout<<dp[a.size()][b.size()]<<endl;
    int maxi=0;
    rep(i,a.size())rep(j,b.size())maxi=max(maxi,dp[i+1][j+1]);
    cout<<maxi<<endl;
  }
}

C++: //AOJ:0528 common sub-string
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s, t; int roop1, ans = 0, memo[4000][4000];
int main() {
	while (cin >> s >> t){
		ans = 0;
		for (int i = 0; i<s.size(); i++){
			for (int j = 0; j<t.size(); j++){
				if (s[i] == t[j]&&memo[i][j]==0){
					memo[i][j]=1;
					roop1 = 1;
					while (1){
						if (s[i + roop1] == 0 || t[j + roop1] == 0){
							break;
						}
						else{
							if (s[i + roop1] == t[j + roop1]){
								memo[i+roop1][j+roop1]=1;
								roop1++;
							}
							else if (s[i + roop1] != t[j + roop1]){
								break;
							}
						}
					}
					ans = max(ans, roop1);
				}
			}
		}
		cout << ans << endl;
		for (int i = 0; i<s.size(); i++){
			for (int j = 0; j<t.size(); j++){
				memo[i][j]=0;
			}
		}
	}
	return 0;
}

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

using namespace std;

short dp[4000][4000];

int main()
{
	for(;;){
		string s, t;
		
		if(!(cin >> s >> t)){
			break;
		}
		
		for(int i = 0; i <= s.size(); i++){
			dp[i][0] = 0;
		}
		
		for(int j = 0; j <= t.size(); j++){
			dp[0][j] = 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;
				}
				else{
					dp[i][j] = 0;
				}
			}
		}
		int ans = 0;
		
		for(int i = 0; i <= s.size(); i++){
			for(int j = 0; j <= t.size(); j++){
				if(dp[i][j] > ans){
					ans = dp[i][j];
				}
			}
		}
		
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int cnt[4100][4100];
int main(){
  string str1,str2;
  while(cin >> str1){
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for(int i=1;i<=len1;i++){
      cnt[i][0] = 0;
    } 
    for(int i=1;i<=len2;i++){
      cnt[0][i] = 0;
    }
    int ret = 0;
    for(int i=1;i<=len1;i++){
      for(int j=1;j<=len2;j++){
	if(str1[i] == str2[j]){
	  cnt[i][j] = cnt[i-1][j-1] + 1;
	}
	else {
	  cnt[i][j] = 0;
	}
	ret = max(ret,cnt[i][j]);
      }
    }
    cout << ret << endl;
  }	
}

C++: #include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    string s,t;
    while(cin>>s>>t){
        int dp[2][4100] = {};
        int ans = 0;
        for(int i = 0;i < s.length();i++){
            for(int j = 0;j < t.length();j++){
                if(s[i] == t[j]){
                    if(i == 0 || j == 0){
                        dp[i%2][j] = 1;
                    }
                    else{
                        dp[i%2][j] = dp[(i+1)%2][j-1] + 1;
                    }
                    ans = max(ans,dp[i%2][j]);
                }
            }
        }
        cout<<ans<<endl;
    }


    return 0;
}