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++: //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=0, save=0, 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= 0;
				while (1){
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
}

C++: #include <bits/stdc++.h>
std::map<std::string,int>mp;
int main(){
    std::string s;
    std::string b;
    
    while(std::cin>>s){
        std::cin>>b;
        mp.clear();
        if(b.size()>s.size())std::swap(s,b);
        for(int i=0;i<s.size();i++){
            for(int j=i+1; j<s.size();j++){
                std::string temp=s.substr(i,j-i);
                mp[temp]=1;
            }
        }
        int ans=0;
        for(int i=0;i<b.size();i++){
            for(int j=i+1; j<b.size();j++){
                std::string comp=b.substr(i,j-i);
                if(mp[comp])ans=std::max(ans,(int)comp.size());
            }
        }
        std::cout<<ans<<std::endl;
    }
}

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

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])+10][strlen(str[1])+10];
    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;
  }
}

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

int dp[4040][4040];

int main()
{
  string a, b;
  while (cin >> a >> b){
    memset(dp, 0, sizeof(dp));

    int max_n = 0;
    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        if (i * j == 0){
          dp[i][j] = a[i] == b[j];
          continue;
        }
        if (a[i] == b[j]) dp[i][j] = 1 + dp[i - 1][j - 1];
      }
    }

    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        max_n = max(max_n, dp[i][j]);
      }
    }

    cout << max_n << endl;
  }
}

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

#define rep(i, n) for(int i=0; i<n; i++)

int dp[2][4444];
string s, t;

int main(int argc, char *argv[])
{
  while(cin >> s >> t){
    int ls = s.length();
    int lt = t.length();
    rep(j, lt) dp[0][j] = dp[1][j] = 0;
    int res = 0;
    rep(i, ls) rep(j, lt){
      if(j == 0) dp[i & 1][0] = 0;
      if(s[i] == t[j]) dp[(i + 1) & 1][j + 1] = dp[i & 1][j] + 1;
      else dp[(i + 1) & 1][j + 1] = 0;
      res = max(res, dp[(i + 1) & 1][j]);
    }
    cout << res << endl;
  }
  
  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;
            }
        }
    }
    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++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0, save[500000]={}, ans = 0;
		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>
#define max(i,j) (i<j?j:i)
int main(void){
	char s[4001],t[4001];
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=0;i+ans<sl;i++){
			for(int j=0;j+ans<tl;j++){
				if(s[i]==t[j]){
					for(int k=1;j+k<tl && i+k<sl;k++){
						ans = max(ans,k);
						if(s[i+k]!=t[j+k])break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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


int solve(const std::string &X, const std::string &Y,
             const int &m, const int &n) {
    int res[m+1][n+1];
    int result = 0;
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 || j == 0) res[i][j] = 0;
            else if (X[i-1] == Y[j-1]) {
                res[i][j] = res[i-1][j-1] + 1;
                result = std::max(result, res[i][j]);
            }
            else res[i][j] = 0;
        }
    }
    return result;
}

int main()
{
    std::string a, b;
    while(std::cin >> a) {
        std::cin >> b;
        int sizea = a.size();
        int sizeb = b.size();
        std::cout << solve(a, b, sizea, sizeb) << std::endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>
#include <set>

#define INF 10 << 10

string str1;
set<string> memo;

string Find(string str) {
	if (memo.find(str) != memo.end()) { return str; }
	if (str1.find(str) != -1) {
		memo.insert(str);
		return str;
	}
	if (str.size() == 1) { return ""; }
	int maxi = 0; string ans;
	string s = str; s.erase(s.begin());
	string ss = Find(s);
	maxi = ss.size(); ans = ss;
	s = str; s.erase(s.begin() + s.size() - 1);
	ss = Find(s);
	if(maxi < ss.size()){
		maxi = ss.size();
		ans = ss;
	}
	memo.insert(ans);
	return ans;
}

int main() {
	string str2;

	while (cin >> str1) {
		cin >> str2;
		//?????????????????? str1 ???
		if (str1.size() < str2.size()) {
			swap(str1, str2);
		}
		int ans = Find(str2).size();
		cout << ans << endl;
	}

	return 0;
}