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++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	string str1, str2;
	while(cin >> str1 >> str2){
		int count = 0;
		for(int i = 0; i < str1.size(); i++){
			for(int j = 0; j < str2.size(); j++){
				int k = 0;
				while(str1.substr(i, k) == str2.substr(j, k)){
					if(i + k > str1.size()-1 || j + k > str2.size()-1) break;
					count = max(count, k);
					k++;
					//cout << str2.substr(i, k) << endl;
				}
			}
		}
		cout << count << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


string s, t;
int lcs[4010][4010];
int main() {
	while (cin >> s >> t)
	{
		lcs[0][0] = 0;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < t.size(); j++) {
				if (s[i] == t[j]) {
					lcs[i+1][j+1] = lcs[i][j] + 1;
				}
				else {
					lcs[i + 1][j + 1] = 0;
				}
			}
		}


		int ans = 0;
		for (int i = 1; i <= s.size(); i++) {
			for (int j = 1; j <= t.size(); j++) {
				ans = max(ans, lcs[i][j]);
			}
		}


		cout << ans << endl;
		
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string a, b;
int dp[4005][4005] = { 0 };
int main() {
	while (cin >> a >> b) {
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < b.size(); j++) {
				if (a[i] == b[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		int res = 0;
		for (int i = 1; i <= a.size(); i++) {
			for (int j = 1; j <= b.size(); j++) {
				res = max(res, dp[i][j]);
			}
		}
		cout << res << 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[6300000]={}, 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<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 4000;
int dp[2][N];

/*
  find substr of txt from word
 */
int solve(string &txt,string &word){
  rep(j,word.size())dp[0][j] = 0,dp[1][j] = 0;
  rep(j,word.size())if (txt[0] == word[j])dp[0][j] = 1;
  int ret = 0;
  REP(i,1,txt.size()){
    rep(j,word.size()){
      if (txt[i] == word[j]){
	dp[1][j] = 1;
	if (j-1 >= 0)dp[1][j] = max(dp[1][j],dp[0][j-1]+1);
      }else dp[1][j] = 0;
      ret = max(ret,dp[1][j]);
    }
    rep(j,word.size()){dp[0][j] = dp[1][j];dp[1][j] = 0;}
  }
  return ret;
}

main(){
  string a,b;
  while(cin>>a>>b){
    cout << solve(a,b)<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define N 4001
int c[N][N];
int lcs(string s,string t){
    int m=s.size();
    int n=t.size();
    int maxl=0;
    s=' '+s;
    t=' '+t;
    for(int i=0; i<=m; i++) for(int j=0; j<=n; j++) c[i][j]=0;
    for(int i=1; i<=m; i++){
        for(int j=1; j<=n; j++){
            if(s[i]==t[j]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=0;
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}

int main(){
    string s,t;
    while(cin>>s>>t){
        cout<<lcs(s,t)<<endl;
    }
}

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


int main()
{
    for(int k=0;k<10;k++){
        string s,t;
        cin >> s >>t;
        int n=(int)s.size();
        int m=(int)t.size();
        int a[n+1][m+1];
        for(int i=0;i<n+1;i++)
            for(int j=0;j<m+1;j++)
                a[i][j]=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                if(s[i]==t[j])
                    a[i+1][j+1]=a[i][j]+1;
        int ma=0;
        for(int i=0;i<n+1;i++){
            for(int j=0;j<m+1;j++)
                ma=max(ma,a[i][j]);
        }
        cout << ma << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
	string s, t;
	while (cin >> s >> t) {
		int s_size = s.size();
		int t_size = t.size();
		int ans = 0;

		for (int i = 0; i < s.size(); i++) {//sをずらしていく
			vector<int>a0(t.size());
			for (int j = 0; j < t.size(); j++) {
				if (j < t.size() && j + i < s.size() && t[j] == s[j + i]) {
					a0[j]++;
				}
				else if (j < t.size() && j + i < s.size() && t[j] != s[j + i]) {
					continue;
				}
			}
			int nagasa = 0;
			int x = 0;
			for (int i = 0; i < t.size(); i++) {
				int nagasa2 = 0;
				x = i;
				while (x < a0.size() && a0[x] == 1) {
					x++;
					nagasa2++;
				}
				nagasa = max(nagasa, nagasa2);
			}
			ans = max(ans, nagasa);
		}

		for (int i = 0; i < t.size(); i++) {//tをずらしていく
			vector<int>a0(s.size());

			for (int j = 0; j < s.size(); j++) {
				if (j < s.size() && j + i < t.size() && s[j] == t[j + i]) {
					a0[j]++;
				}
				else if (j < s.size() && j + i < t.size() && s[j] != t[j + i]) {
					continue;
				}
			}
			int nagasa = 0;
			int x = 0;
			for (int i = 0; i < t.size(); i++) {
				int nagasa2 = 0;
				x = i;
				while (x < a0.size() && a0[x] == 1) {
					x++;
					nagasa2++;
				}
				nagasa = max(nagasa, nagasa2);
			}
			ans = max(ans, nagasa);
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  string str,str2;
  while(cin >> str >> str2){
    if(cin.eof())break;
    int ans = 0,t=1;
    for(int i = 0 ; i < str.size()-1 ; i++){
      for(int j = t ; i+j < str.size() ; j++){
	if(str2.find(str.substr(i,j)) != string::npos ){
	  if(ans < j){
	    ans = j;
	    t = ans;
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 4001
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(scanf("%s",&s)){
  ZERO(dp);
  scanf("%s",&t);
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d",ma);
 }
}

int main(){
 solve();
 return 0;
}