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++: 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;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

/*
int main(){
	int n,k;
	while(cin>>n>>k&&n!=0&&k!=0){
		vector<int> card(n+1);
		vector<int> flag(n+1);
		flag[0]=-1;
		card[0]=-1;
		for(int i=0;i<k; ++i){
			int tmp;
			cin >> tmp;
			card[tmp]=tmp;
			flag[tmp]=1;
		}
		int ans=0;
		if(flag[0]!=0){
			int cnt=0;
			int s;
			int n;
			for(int i=1;i<=n; ++i){
				if()
			}
		}
	}
	return 0;
}*/

int main(){
	string A,B;
	while(cin>>A>>B){
		int ans=0;
		for(int i=0; i<A.size(); ++i){
			for(int j=ans; i+j<=A.size(); ++j){
				string tmp=A.substr(i,j);
				/*for(int k=i;k<j; ++k){
					tmp+=A[k];
				}*/
				int a=tmp.size();
				if(B.find(tmp)!=-1) ans=max(ans,a);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

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

int dp[4444][4444];
 
int main(){

  string str1, str2;
 
  while(cin >> str1 >> str2){
   
 
    memset(dp,0,sizeof(dp));
 
    for(int i = 1; i <= str1.size(); i++){
      for(int j = 1; j <= str2.size(); j++){
        if(str1[i-1] == str2[j-1]){
          dp[i][j] = dp[i-1][j-1] + 1;
        }else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
    cout << dp[str1.size()][str2.size()] << endl;
 
  }
}

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

using namespace std;

int main() {
    string s1, s2;
    while(cin >> s1 >> s2) {
        vector<vector<int> > dp(s1.size(), vector<int>(s2.size(), 0));

        int ans = 0;
        int l1 = s1.size();
        int l2 = s2.size();
        for(int i = 0; i < l1; ++i) {
            for(int j = 0; j < l2; ++j) {
                if(s1[i] == s2[j]) {
                    if(i > 0 && j > 0) dp[i][j] = dp[i-1][j-1]+1;
                    else dp[i][j] = 1;
                }
                if(dp[i][j] > ans) ans = dp[i][j];
            }
        }
        cout << ans << endl;
    }
    return 0;
}