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

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()

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

		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 <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int left_length,right_length,max,tmp,left_start,left_end,right_start,right_end,k;
	char left[4001],right[4001];

	while(scanf("%s",left) != EOF){
		scanf("%s",right);

		for(left_length = 0;left[left_length] != '\0';left_length++);
		for(right_length = 0; right[right_length] != '\0';right_length++);

		max = 0;
		if(right_length > left_length){

			for(right_end = 1;right_end <= left_length;right_end++){
				tmp = 0;
				for(left_start = left_length-right_end,k=0; k < right_end; k++){
					if(left[left_start+k] == right[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(right_end = left_length;right_end < right_length;right_end++){
				tmp = 0;
				for(right_start = right_end-left_length,k=0;right_start + k < right_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(left_end = left_length-1;left_end >= 1; left_end--){
				tmp = 0;
				for(right_start = right_length-left_end,k=0;k < left_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			printf("%d\n",max);

		}else{

			for(left_end = 1;left_end <= right_length;left_end++){
				tmp = 0;
				for(right_start = right_length-left_end,k=0; k < left_end; k++){
					if(right[right_start+k] == left[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(left_end = right_length;left_end < left_length;left_end++){
				tmp = 0;
				for(left_start = left_end-right_length,k=0;left_start + k < left_end; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(right_end = right_length-1;right_end >= 1; right_end--){
				tmp = 0;
				for(left_start = left_length-right_end,k=0;left_start + k < left_length; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

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

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int ans=0;
int cal(string s1,string s2,int s,int p)
{
	int cnt=0;
	for(int i=p;i<s2.size();i++)
	{
		if(s1[i+s]==s2[i])cnt++;
		else break;
	}
	return cnt;
}
int main()
{
	while(1)
	{
		string s1,s2;
		cin >> s1 >> s2;
		if(cin.eof())break;
		ans=0;
		for(int i=0;i<s1.size();i++)
		{
			for(int j=0;j<s1.size()-i;j++)
			{
				if(s2[j]==s1[j+i])
				{
					ans=max(ans,cal(s1,s2,i,j));
				}
			}
		}
		cout << ans << endl;
		s1.clear();
		s2.clear();
	}
	return 0;
}

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

int main(){
	string s,t;
	while(cin >> s >> t){
		int ma = 0;
		int dp[4001][4001] = {};
		for(int i = 0;i < s.length();i++){
			for(int j = 0;j < t.length();j++){
				if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
				ma = max(ma,dp[i + 1][j + 1]);
			}
		}
		cout << ma << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
string a,b;
int c,d;
int dp[2][5000],ans;
int main(){
  while(cin>>a>>b){
    c=a.size(),d=b.size();
    ans=0;
    for(int i=0;i<2;i++)
      for(int j=0;j<5000;j++)dp[i][j]=0;
    for(int i=1;i<=c;i++){
      for(int j=1;j<=d;j++){
	int ni=i%2,ri=1-i%2;
	if(a[i-1]==b[j-1])dp[ni][j]=dp[ri][j-1]+1;
	else dp[ni][j]=0;
	ans=max(ans,dp[ni][j]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
		string s, t; int roop1=0, roop2 = 0,roop3, save[1000000]={}, ans = 0;
	while(1){
	
		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>

char a[4004],b[4004];

int solve(char *s,char *t,int lenS,int lenT){
  int i,j;
  int count = 0;
  int res = 0;

  for(i=j=0;i<lenS && j<lenT;i++,j++){
    if(s[i] == t[j]){
      count++;
    }
    else{
      if(res < count) res = count;
      count = 0;
    }
  }

  if(res < count) res = count;
  return res;
}

int main(void){
  int i,j;
  int lenA,lenB;
  int ans,tmp;

  while(scanf("%s%s",a,b) != EOF){
    lenA = strlen(a);
    lenB = strlen(b);
    ans = 0;

    //AÌæªÌi¶ðíÁ½¶ñÆ,Bðär
    for(i=0;i<lenA;i++){
      tmp = solve(&a[i],b,lenA-i,lenB);
      if(ans < tmp) ans = tmp;
    }

    //BÌæªÌi¶ðíÁ½¶ñÆ,Aðär
    for(i=0;i<lenB;i++){
      tmp = solve(&b[i],a,lenB-i,lenA);
      if(ans < tmp) ans = tmp;
    }

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

  return 0;
}