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.h>
#include <algorithm>
using namespace std;

int main() {
  while(1) {
    char str[2][4001];
    int state;
    state = scanf("%s\n", str[0]);
    if(state == EOF) break;
    scanf("%s\n", str[1]);

    int data[strlen(str[0])+1][strlen(str[1])+1];
    int maxL = 0;
    for(int i = 0; i <= strlen(str[0]); i++) {data[i][0] = 0;}
    for(int j = 0; j <= strlen(str[1]); j++) {data[0][j] = 0;}

    for(int i = 1; i <= strlen(str[0]); i++) {
      for(int j = 1; j <= strlen(str[1]); j++) {
	//if(str[0][i-1] == str[1][j-1]) data[i][j] = data[i-1][j-1]+1;
	//else     data[i][j] = 0;

	if(data[i][j] > maxL) maxL = data[i][j];
      }
    }
    cout << maxL << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;

int dp[4001][4001];
char s1[4001], s2[4001];

int main() {
  while (scanf("%s", s1) != EOF) {
    scanf("%s", s2);
    int ans = 0;
    for (int i = 0; s1[i] != 0; i++) {
      for (int j = 0; s2[j] != 0; j++) {
        dp[i][j] = 0;
        if (s1[i] == s2[j]) {
          if (i == 0 || j == 0) dp[i][j] = 1;
          else dp[i][j] = dp[i - 1][j - 1] + 1;
        }
        ans = max(ans, dp[i][j]);
      }
    }
    printf("%d\n", ans);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	while(true){
		cin>>a>>b;
		if(cin.eof())	return 0;
		int ans=0;
		for(int i=0;i<(int)a.size();i++){
			for(int j=0;j<(int)b.size();j++){
				int temp=0;
				while(i+temp<(int)a.size()&&j+temp<(int)b.size()&&a[i+temp]==b[j+temp])	temp++;
				ans=max(ans,temp);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    while(sc.hasNext()){
      char[] s1 = sc.next().toCharArray();
      char[] s2 = sc.next().toCharArray();
      int len1 = s1.length;
      int len2 = s2.length;

      //intテ・ツ楪凝」ツ?ァ, 4000*4000テ」ツつ津ァツ「ツコテ、ツソツ敕」ツ?凖」ツつ?-> MLE
      //shortテ・ツ楪凝」ツ?繰avaテ」ツ?ァテ、ツスツ陛」ツδ静」ツつ、テ」ツδ暗」ツ?凝、ツクツ催ヲツ伉偲」ツ??」ツ?古ィツゥツヲテ」ツ??-> MLE
      //テ、ツサツ陛ヲツ鳴ケテ」ツ?古」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァテ」ツ??ゥツ?催・ツ按療ッツシツ妥ィツ。ツ古」ツつ津、ツスツソテ」ツ??・ツ崢榲」ツ?凖・ツスツ「テ」ツ?ォ
      short[][] dp = new short[2][len2 + 1];
      short maxLen = 0;

      for(int idx1 = 0; idx1 < len1; idx1++){
        int i = idx1 % 2;
        int ni = (i + 1) % 2;

        Arrays.fill(dp[ni], (short)0);

        for(int idx2 = 0; idx2 < len2; idx2++){
          if(s1[idx1] == s2[idx2]){
            dp[ni][idx2 + 1] = (short)(dp[i][idx2] + 1);
            maxLen = (short)Math.max(maxLen, dp[ni][idx2 + 1]);
          }
        }
      }

      System.out.println(maxLen);
    }
  }
}

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

char A[4002],B[4002];
short int length[4000][4000];
int mmax[200],mcor = 0;
int main(){
	int i,j,k,lenA,lenB;
	while(cin >> A[0]){
		cin >> A+1;
		cin >> B;
		lenA = strlen(A);
		lenB = strlen(B);
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				length[i][j] = -1;
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				for(k = 0;;k++){
					if(i+k >= lenA || j+k >= lenB || A[i+k] != B[j+k]){
						length[i][j] = k;
						break;
					}
					else if(length[i+k][j+k] >= 0){
						length[i][j] = length[i+k][j+k]+k;
					}
				}
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(mmax[mcor] < length[i][j])
					mmax[mcor] = length[i][j];
			}
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		cout << mmax[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	string str,str2;
	vector<short int> array[4001];
	int i,j;
	
	for(i=0;i<4001;i++)
	{
		for(j=0;j<4001;j++)
		{
			array[i].push_back(0);
		}
	}
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		int ans=0;
		for(i=1;i<=str.size();i++)
		{
			for(j=1;j<=str2.size();j++)
			{
				array[i][j]=0;
				if(str[i-1]==str2[j-1])
				{
					array[i][j]=array[i-1][j-1]+1;
				}
				if(ans<array[i][j])
					ans=array[i][j];
			}
		}
		cout << ans << endl;
	}
}

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

string str1;
string str2;
int solve(){
    int count=0;
    int m=0;
    int limit1;
    int limit2;
    int limit;
    limit1 = str1.size();
    limit2 = str2.size();
    for(int i=0;i<limit2;i++){
        limit = i+limit1<limit2 ? i+limit1 : limit2;
        for(int j=i;j<limit;j++){
            cout << str1[j-i] << str2[j];
            if(str1[j-i] == str2[j]){
                count++;
            }else{
                m = max(m, count);
                count = 0;
            }
        }
    }
    return m;
}
int main(){
    string temp;
    while(cin >> str1 >> str2){
        if(str1.size() > str2.size()){
            temp = str1;
            str1 = str2;
            str2 = temp;
        }
        cout << solve() << endl;
    }
}

C++: 

#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s1, s2;

int main()
{
	while (cin >> s1 >> s2) {
		set<string> s;
		string s3;

		for (int i = 0; i < s1.size(); i++) {
			for (int j = i; j < s1.size(); j++) {
				for (int k = i; k < j + 1; k++) {
					s3 += s1[k];
				}
				s.insert(s3);
				s3 = "";
			}
		}
		int ans = 0;
		for (set<string>::iterator itr = s.begin(); itr != s.end(); ++itr) {
			int pos = s2.find(*itr);
			string s3 = *itr;
			int si = s3.size();
			if (pos != -1)ans = max(ans,si);
		}
		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;
	while(cin>>s>>t){
		 int roop1, roop2 = 0, save[10000], 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[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;
}