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() {
	while(true){
		string s, t; int roop1=0, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s==""||t=="")
		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<bits/stdc++.h>
using namespace std;
int ans,s1,s2,text_here,patn_here,text_len,patn_len;
string str1,str2;

int main(){
    //EOF?????\????????§??????
    while(cin >> str1 >> str2){
            //?????£???????¨??????????
            int s1=str1.size();
            int s2=0;
        //???????°??????§??\????????????
        while(s1!=0 || s2<=str2.size()){

            if(s1!=0){
                s1--;
            }else{
                s2++;
            }
            text_here=0;
            patn_here=0;
            text_len=str1.size();
            patn_len=str2.size();

            while(text_here<text_len && patn_here<patn_len){
                if(str1[s1+text_here]==str2[s2+patn_here]){
                    patn_here++;
                    text_here++;
                    ans=max(patn_here,ans);
                }else{
                    text_here++;
                    patn_here=0;
                }

            }
        }
        cout << ans << endl;
        ans=0;
    }

return 0 ;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,i,j,max;
  string s1,s2,t;
  while(cin>>s1>>s2){
    max=0;
    for(i=0;i<=s1.size();i++){
      if(s1.size()-max<0)break;
      for(j=1;j<=s1.size()-i;j++){
	t=s1.substr(i,j);
	if(s2.find(t)!=string::npos)
	  if(max<t.size())max=t.size();
      }
    }
    cout<<max<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

signed main(){
    string s,t;
    while(cin >> s){
        cin >> t;
        auto dp = vector<vector<int>>(s.size() + 1, vector<int>(t.size() + 1,0LL));
        for(int i = 0; i < s.size(); ++i){
            for(int j =0; j < t.size();++j){
                if(s[i] == t[j])
                    dp[i + 1][j + 1] =  dp[i][j] + 1;
            }
        }
        int maxi = -1;
        for(auto u : dp)
            for(auto e : u)
                cmax(maxi,e);
        cout << maxi << endl;
    }
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	static int dp[4010][4010] = {};
	for (string A, B; cin >> A >> B;) {
		memset(dp, 0, sizeof(dp));
		rep(i, 0, A.size()) rep(j, 0, B.size()) {
			if (A[i] == B[j])
				dp[i + 1][j + 1] = dp[i][j] + 1;
			else
				dp[i + 1][j + 1] = 0;
		}
		cout << *max_element(dp[0], dp[4010]) << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int MAX = 5000;
string s, t;
int dp[MAX + 1][MAX + 1];

int main(void) {
  while (cin >> s >> t) {
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
        dp[i][j] = 0;
      }
    }
    int ans = 0; 
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(dp[i + 1][j + 1], ans);
        } else
          dp[i + 1][j + 1] = 0;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int DP[4096][4096];
int main() {
	string s, t;
	while(cin >> s >> t){
		memset(DP, 0, sizeof(DP));
		int n = s.size(), m = t.size(), ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				if(s[i] == t[j]){
					DP[i + 1][j + 1] = DP[i][j] + 1;
					ans = max(DP[i + 1][j + 1], ans);
				}
				else{
					DP[i + 1][j + 1] = 0;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))

const int MAX_LEN = 4000;
int dp[MAX_LEN+1][MAX_LEN+1];

void solve(string s, string t) {
    int n = s.size(), m = t.size();
    rep(i,n+1) rep(j,m+1) {
        if(i==0 or j==0) {
            dp[i][j] = 0;
        } else if(s[i] == t[j]) {
            if(s[i-1] == t[j-1]) 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]));
        }
    }

    cout << dp[n][m] << "\n";

    return ;
}

int main() {
    string s, t;
    while(cin>>s>>t) {
        ZERO(dp);
        solve(s,t);
    }

    return 0;
}

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

int main(){
	int max_comp_len;
	int i,j;
	bool hit;
	string str1, str2;
	while(cin>>str1){
		cin>>str2;
		if(str1.length() < str2.length()){
			max_comp_len = str1.length();
		}else{
			max_comp_len = str2.length();
		}
		hit = false;
		while(true){
			for(i = 0; i <= str1.length() - max_comp_len ; i++){
				for(j = 0; j <= str2.length() - max_comp_len; j++){
					if( str1.compare( i, max_comp_len, str2, j, max_comp_len) == 0){		//hit
						hit = true;			//V
						i = str1.length();	//V
						break; 			//for*2&while loop end
					}
				}
			}
			if((hit == true) || (max_comp_len <= 0)){
				break;
			}else{
				max_comp_len--;
			}
		}
		
		cout<< max_comp_len << endl;
	}
	return 0;
}