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++: //JOI 0528 Common Sub-String
#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;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

int dp[4020][4020];

int main() {
	string s1, s2;
	while(cin >> s1 >> s2) {
		memset(dp, 0, sizeof(dp));
		int ans = 0;
		FOR(i, 0, s1.size()) {
			FOR(j, 0, s2.size()) {
				if(s1[i] == s2[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = max(ans, dp[i + 1][j + 1]);
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    string n, m;
    while(cin >> n >> m){
        int ans = 0;
        if(n.size() > m.size()) swap(n, m);
        for(int i=0; i < n.size(); i++){
            for(int j=i+1; j < n.size(); j++){
                if(j-i <= ans) continue;
                string s = n.substr(i, j-i);
                if(m.find(s) != string::npos){ans = max(ans, (int)s.size());}
                else j = 40000;
            }
        }
        cout << ans << endl;
    }
}

C++: 
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#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;

char a[4010], b[4010];
int dp[4010][4010];

int main()
{
	while (cin >> a) {
		cin >> b;
		int len_a = strlen(a);
		int len_b = strlen(b);
		for (int i = 0; i <= len_a; i++)
			for (int j = 0; j <= len_b; j++)
				dp[i][j] = 0;
		for (int i = 0; i < len_a; i++) {
			for (int j = 0; j < len_b; j++) {
				if (a[i] == b[j])
					dp[i + 1][j + 1] = dp[i][j] + 1;
			}
		}
		int ans = 0;
		for (int i = 0; i <= len_a; i++)
			for (int j = 0; j <= len_b; j++)
				ans = max(ans, dp[i][j]);
		cout << ans << endl;
	}
	return 0;
}

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

int dp[4005][4005];

int main() {
	string s;
	while (cin >> s) {
		string sa;
		cin >> sa;
		for (int i = 0; i < 4002; i++)
			for (int j = 0; j < 4002; j++)dp[i][j] = 0;
		s.push_back('@');
		int ans = 0;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < sa.size(); j++) {
				int a = s.size();
				int I = min(a-1, i + j);
				if (s[I] == sa[j]) {
					dp[I][j + 1] = dp[I-1][j] + 1;
					ans = max(ans, dp[I][j + 1]);
				}
				else dp[I][j + 1] = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	char a[4000],b[4000];
	while(scanf("%s",a)!=EOF){
		scanf("%s",b);
	int t[4002][4002];
	for(int i=0;i<=strlen(a);i++){
		t[0][i]=0;
	}
	for(int j=0;j<=strlen(b);j++){
		t[j][0]=0;
	}
	for(int i=1;i<=strlen(a);i++){
		for(int j=1;j<=strlen(b);j++){
			if(a[i-1]==b[j-1])t[i][j]=t[i-1][j-1]+1;
			else t[i][j]=0;
		}
	}

	int ans=0;
	for(int i=1;i<=strlen(a);i++){
		for(int j=1;j<=strlen(b);j++){
			ans=max(ans,t[i][j]);
		}
	}
	cout << ans << "\n";
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	while(true) {
		
		char str1[4096], str2[4096];
		
		if(scanf("%s", str1) == EOF)
			break;
		scanf("%s", str2);
		
		int len1 = strlen(str1), len2 = strlen(str2);
		int ans = 0;
		static int dp[2][4096] = {0};
		
		for(int i = 0; i <= len1; ++i)
			dp[0][i] = 0;
		
		int *cur = dp[0];
		int *next = dp[1];
	
		for(int i = 1; i <= len1; ++i) {
			
			
			cur[0] = 0;
			
			for(int j = 1; j <= len2; ++j) {
				if(str1[i - 1] == str2[j - 1]) {
					next[j] = cur[j - 1] + 1;
					ans = max(next[j], ans);
				} else {
					next[j] = 0;
				}
			}
			
			swap(cur, next);
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

C++: #include<iostream>

using namespace std;

string s1,s2;

int solve(int a, int b){
  int pass = 0;
  while(s1[a++] == s2[b++] && a < s1.length() && b < s2.length()) pass++;

  return pass;
}

int main(){
  while(cin >> s1 >> s2){
    int ans = 0;
    for(int i = 0; i < s1.length(); i++)
      for(int j = 0; j < s2.length(); j++)
	ans = max(ans,solve(i,j));

    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  string s, t;
  while(cin >> s){
    cin >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
      string sub_s = s.substr(i, s.length() - i);
      int cnt = 0;
      for(int j = 0; j < min(sub_s.length(), t.length()); j++){
	if(sub_s[j] == t[j]){
	  cnt++;
	  if(cnt > ans) ans = cnt;
	}else{
	  cnt = 0;
	}
      }
    }
    for(int i = 0; i < t.length(); i++){
      string sub_t = t.substr(i, t.length() - i);
      int cnt = 0;
      for(int j = 0; j < min(sub_t.length(), s.length()); j++){
	if(sub_t[j] == s[j]){
	  cnt++;
	  if(cnt > ans) ans = cnt;
	}else{
	  cnt = 0;
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}