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++: #include <bits/stdc++.h>
using namespace std;

int dp[4000][4000];
 
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 <set>
#include <algorithm>

std::string s1,s2;

std::set<std::string> set;

int main() {
    
    while(std::cin>>s1>>s2) {
        
        int ans=0;
        
        for(int i=0;i<s1.size();++i){
            for(int j=i;j<s1.size();++j)
                set.emplace(s1.substr(i,j-i+1));
        }
        
        for(int i=0;i<s2.size();++i){
            for(int j=i;j<s2.size();++j){
                if(set.count(s2.substr(i,j-i+1)))
                    ans=std::max(ans,j-i+1);
            }
        }
        
        std::cout<<ans<<std::endl;
    }
    
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    string s, t;
    while (cin >> s >> t) {
        int dp[4000][4000];
        for (int j = 0; j < 4000; ++j) {
            fill(dp[j], dp[j] + 4000, 0);
        }

        int ret = 0;

        for (int j = 0; j < s.size(); ++j) {
            for (int k = 0; k < t.size(); ++k) {
                if (s[j] != t[k]) {
                    dp[j][k] = 0;
                } else if (j == 0 || k == 0) {
                    dp[j][k] = 1;
                } else {
                    dp[j][k] = dp[j-1][k-1] + 1;
                }

                ret = max(ret, dp[j][k]);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define SQR(a) ((a)*(a))
using namespace std;
typedef long long int ll;
typedef pair<int,int> pr;
typedef pair<pr,ll> ppr;
typedef vector<pr> vpr;
const int INF=1<<30;
int main() {
	string s1,s2;
	while(cin >>s1 >> s2){
	int maxim=0;
	REP(i,s1.size())
		REP(j,s2.size())
			REP(k,INF){
				if(i+k<s1.size() && j+k<s2.size() && s1[i+k]==s2[j+k])
				continue;
				maxim=max(maxim,k);
				break;
			}
	cout << maxim << endl;
	}
	// your code goes here
	return 0;
}

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

int count(string& a, string& b) {
    int a_len = a.length();
    int b_len = b.length();
    int max_lcs = 0;
    int cur_lcs = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len && i + j < a_len; j++) {
            if (a[i+j] == b[j]) {
                cur_lcs++;
            } else {
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }
    for (int i = 0; i < b_len; i++) {
        for (int j = 0; j < a_len && i + j < b_len; j++) {
            if (a[j] == b[i+j]) {
                cur_lcs++;
            } else {
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }

    return max_lcs;
}

int main() {
    string a, b;
    while (cin >> a >> b) {
        cout << count(a, b) << endl;
    }
    return 0;
}

C++: #include<stdio.h>#include <string.h>
short dp[4001][4001]={},ans=0;char str1[2][4005];int main(){while(scanf("%s",str1[0])!=-1){scanf("%s",str1[1]);int a=strlen(str1[0]),b=strlen(str1[1]); for(int i=0;i<a;i++){for(int j=0;j<b;j++){if(str1[0][i]==str1[1][j]){if(!i || !j){dp[i][j]=1;if(!ans){ans++;}}else{dp[i][j]=1+dp[i-1][j-1];ans=ans<dp[i][j]?dp[i][j]:ans;}}}}printf("%d\n",ans); ans=0;memset(dp,0,sizeof(dp));}return 0;}

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

int main(){
	string s,t;
	while( cin >> s >> t ){
		int ans = 0;
		
		for(int i=0 ; i < s.size() ; i++ ){
			string s_ = s.substr(i);
			int len = min( s_.size() , t.size() );
			int a[4001] = {0};
			
			for(int j=0 ; j < len ; j++ ){
				if( s_[j] == t[j] ) a[j] = 1;
			}
			
			int sum=0;
			for(int j=1 ; j < len ; j++ ){
				if( a[j-1] > 0 && a[j] > 0 ){
					a[j] = a[j-1] + 1;
					sum = max( sum , a[j-1] + 1 );
				}
			}
			ans = max( ans , sum );
		}
		cout << ans << endl;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	string a, b;
	while (cin >> a >> b;) {
		int dp[4001][4001];
		for (int i = 0; i < 4001; ++i) {
			for (int j = 0; j < 4001; ++j) {
				dp[i][j] = -1e9;
			}
		}
		dp[0][0] = 0;
		int ans = 0;
		for (int i = 0; i < a.size(); ++i) {
			for (int j = 0; j < a.size(); ++j) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
					else {
						dp[i][j] = 1;
					}

				}
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int lcs(string &a,string &b){
	int r=0,t;
	rep(i,a.size())rep(j,b.size()){
		t=0;while(i+t<a.size()&&j+t<b.size()&&a[i+t]==b[j+t])t++;
		if(t>r)r=t;
	}
	return r;
}
int main(){
	string a,b;
	while(cin>>a>>b)cout<<lcs(a,b)<<endl;
}

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

int main(){
	string s[10000];
	int i = 0;
	while(1) {
		cin >> s[i];
		i++;
		if (cin.eof()) { break; }
	}
	int max = 0;
	int tmp = 0;
	for(int j = 0; j < i/2; j++){
		string s1 = s[j*2];
		string s2 = s[j*2+1];
		if (s1.length() > s2.length()) {
			string ss = s1;
			s1 = s2;
			s2 = ss;
		}
		max = 0;
		for (int k = 0; k < s1.length(); k++) {
			for (int l = 0; l < s2.length(); l++) {
				tmp = 0;
				if (s1.at(k) == s2.at(l)) {
					tmp++;
					for (int m = k+1; m < s1.length(); m++) {
						if (s2.length() <= l + m - k || s1.length() <= m) {
							break;
						}
						if (s1.at(m) == s2.at(l + m - k)) {
							tmp++;
						} else {
							break;
						}
					}
					
					if (max < tmp) {
						max = tmp;
					}
				}
			}
		}
		cout << max << endl;
	}
}