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 <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();
    if (a_len < b_len) {
        swap(a, b);
        swap(a_len, b_len);
    }
    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;
            }
        }
    }
    return max_lcs;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

string s, t;
int n, m;
int dp[4001][4001];

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while (cin >> s >> t) {
        n = s.size(); m = t.size();
        int ans = 0;
        rep(i, n) {
            rep(j, m) {
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    chmax(ans, dp[i + 1][j + 1]);
                }
                else {
                    dp[i][j] = 0;
                }
            }
        }
        cout << ans << endl;
    }
}

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

			//left???????????¨right???????????????????????§
			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;
					}
				}
			}

			//left???????????¨right???????????????????????§
			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;
					}
				}
			}

			//left_end???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{

			//right???????????¨left???????????????????????§
			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;
					}
				}
			}

			//right???????????¨left???????????????????????§
			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;
					}
				}
			}

			//right_end???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 <iostream>
#include <string>
#include <map>
#include <queue>
using namespace std;

int main()
{
	int lt,ls,lmax;
	char ct[4001],cs[4001];
	map<string,bool> made;
	string t,s,stemp[2];
	queue<string> que;

	while(scanf("%s",ct)  != EOF){
		scanf("%s",cs);
		t.append(ct);
		s.append(cs);

		if(t.length() < s.length()){
			t.swap(s);
		}

		que.push(s);
		made.insert(make_pair(s,true));
		while(!que.empty()){
			stemp[0] = que.front();
			stemp[1] = stemp[0];
			if(t.find(stemp[0]) != string::npos){
				break;
			}

			stemp[0].erase(stemp[0].begin());
			stemp[1].erase(stemp[0].length(),1);
			for(int c = 0; c < 2; c++){
				if(made.find(stemp[c]) == made.end()){
					made.insert(make_pair(stemp[c],true));
					que.push(stemp[c]);
				}
			}
			que.pop();
		}

		if(que.empty()){
			cout << 0 << endl;
		}
		else{
			cout << que.front().length() << endl;
			while(!que.empty()){
				que.pop();
			}
			made.clear();
			t.clear();
			s.clear();
		}
	}

	return 0;
}

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