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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short dp[4001][4001]={};
char str1[4005],str2[4005];
short ans=0;
int main(){
	while(scanf("%s",str1)!=EOF){
		scanf("%s",str2);
int a=strlen(str1),b=strlen(str2);
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,dp[i][j]);} 
		 else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}}
  printf("%d\n",ans); }return 0;}

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

int main() {
	std::string a, b;

	while (std::cin >> a) {
		std::cin >> b;
		std::vector<std::vector<int>> memo(a.size() + 1, std::vector<int>(b.size() + 1, 0));
		int max = 0;
		for (auto apos = 1; apos <= a.size(); ++apos) for (auto bpos = 1; bpos <= b.size(); ++bpos){
			if (a[apos - 1] == b[bpos - 1]) {
				memo[apos][bpos] = memo[apos - 1][bpos - 1] + 1;
				if (memo[apos][bpos] > max)
					max = memo[apos][bpos];
			}
		}
		std::cout << max << std::endl;
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int main() {

	string s, t;
	while (cin >> s >> t) {
		int dp[4040][4040] = {};
		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;
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < s.size() + 1; i++) {
			for (int j = 0; j < t.size() + 1; j++) {
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
}

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++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-8;

short dp[4001][4001];

int main(){
	string str1;
	while(cin>> str1){
		memset(dp,0,sizeof(dp));

		string str2;
		cin >> str2;

		for(int i=0;i<str1.size();i++){
			for(int j=0;j<str2.size();j++){
				if(str1[i] == str2[j]){
					dp[i+1][j+1] = dp[i][j]+1;
				}
				else{
					dp[i+1][j+1] = 0;
				}
			}
		}

		short res=0;
		for(int i=0;i<str1.size();i++){
			for(int j=0;j<str2.size();j++){
				res = max(res,dp[i][j]);
			}
		}

		printf("%d\n",res);
	}
}

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]));
            dp[i][j] = 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 <bits/stdc++.h>

using namespace std;

int dp[4010][4010];

int main(void) {
  string s, t;
  while (cin >> s >> t) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
        if (s[i] != t[j]) continue;
        dp[i + 1][j + 1] = dp[i][j] + 1;
      }
    }

    int ans = 0;
    for (int i = 1; i <= s.size(); i++) {
      for (int j = 1; j <= t.size(); j++) {
        ans = max(ans, dp[i][j]);
      }
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include "stdio.h"
#include "string.h"

char st1[5000];
char st2[5000];
char flg[5000];
int ans[1000];

int main()
{
  int nw = 0;
  while(1)
    {
      gets(st1);
      if(st1[0] == EOF)
	{
	  break;
	}
      gets(st2);
      int st1l,st2l;
      st1l = strlen(st1) - 1;
      st2l = strlen(st2) - 1;
      int m = 0;
      for(int i = 0; i < st1l; i++)
	{
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      flg[ii] = 0;
	    }
	  for(int ii = i; ii < st1l; ii++)
	    {
	      flg[ii] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      flg[ii] = flg[ii] - st2[ii];
	    }
	  int n = 0;
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}