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>
using namespace std;

int main(){
  string str1, str2;
  while(cin >> str1 >> str2){
    int ans=0;
    for(int i=0;i<str1.length();i++){
      string temp=str1.substr(i, str1.length()-i);
      int count=0;
      for(int j=0;j<min(temp.length(), str2.length());j++){
	if(temp[j]==str2[j]) count++;
	else count=0;
	ans=max(ans, count);
      }
    }
    for(int i=0;i<str2.length();i++){
      string temp=str2.substr(i, str2.length()-i);
      int count=0;
      for(int j=0;j<min(temp.length(), str1.length());j++){
	if(temp[j]==str1[j]) count++;
	else count=0;
	ans=max(ans, count);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

int main() {
    string s, t;
    while(cin>>s>>t) {
        set<string> st;
        int n = s.size(), m = t.size();
        rep(i,n) {
            for(int len=1; i+len < n; len++) {
                st.insert(s.substr(i, len));
            }
        }

        int ans = 0;
        rep(i,m) {
            for(int len=1; i+len < m; len++) {
                if(st.count(t.substr(i,len)) == 0) continue;
                ans = max(ans, len);
            }
        }

        cout << ans << "\n";
    }

    return 0;
}

C++: #include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string,int> m;
int main(){
	string s,t;
	while(cin >> s >> t){
		int a=0,S=s.size(),T=t.size(),i,j;
		for(j=min(S,T);j>=1;j--){
			for(i=0;i<S-j;i++) m[s.substr(i,j)]++;
			for(i=0;i<T-j;i++) if(m[t.substr(i,j)]>=1) a=max(a,j);
			m.clear();
			if(a)break;
		}
		cout<<a<<endl;
	}
}

C++: //AOJ:0528 common sub-string
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s, t; int roop1, ans = 0, memo[4000][4000];
int main() {
	while (cin >> s >> t){
		ans = 0;
		for (int i = 0; i<s.size(); i++){
			for (int j = 0; j<t.size(); j++){
				if (s[i] == t[j]&&memo[i][j]==0){
					memo[i][j]=1;
					roop1 = 1;
					while (1){
						if (s[i + roop1] == 0 || t[j + roop1] == 0){
							break;
						}
						else{
							if (s[i + roop1] == t[j + roop1]){
								memo[i+roop1][j+roop1]=1;
								roop1++;
							}
							else if (s[i + roop1] != t[j + roop1]){
								break;
							}
						}
					}
					ans = max(ans, roop1);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s,t;
set<string>st;
int dp[4444][4444];
int main(){
	while(cin>>s>>t){
		s="@"+s;
		t="@"+t;
		int ans=0;
		memset(dp,0,sizeof(dp));
		for(int i=1;i<s.size();i++){
			for(int j=1;j<t.size();j++){
				if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
				ans=max(ans,dp[i][j]);
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>

#define reps(i,j,k) for(int i = j; i < k ;i++)
#define rep(i,j) reps(i,0,j)

using namespace std;
int dp[4012][4012];
int main(){
    string str1,str2;
    while(cin >> str1 >> str2){
        memset(dp,0,sizeof(dp));
        int h = str1.size();
        int w = str2.size();
        int ma = -100000;
        rep(i,h){
            rep(j,w){
                if(i==0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(j == 0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(str1[i] == str2[j])dp[i][j] += dp[i-1][j-1]+1;
                ma = max(ma,dp[i][j]);
            }
        }
        printf("%d\n",ma);
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

short dp[4001][4001];

int main(){
	while(1){
		string a,b;
		cin>>a>>b;
		
		if(b.size()==0){
			break;
		}
		
		rep(i,4001)rep(j,4001)dp[i][j]=0;
		
		int maxi=0;
		reps(i,a.size()){
			reps(j,b.size()){
				if(a[i-1]==b[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				maxi=max(maxi,dp[i][j]);
			}
		}
		
		printf("%d\n",maxi);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    string a, b;
    if (!(cin >> a)) return 0;
    cin >> b;
    int result = 0, dp[4001];
    fill(dp, dp+b.length()+1, 0);
    for (int i = 0; i < a.length(); i++)
      for (int j = b.length()-1; j >= 0; j--)
        if (a[i] == b[j]) {
          dp[j+1] = dp[j] + 1;
          if (dp[j+1] > result)
            result = dp[j+1];
        } else dp[j+1] = 0;
    cout << result << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    while(true){
        string s1, s2;
        cin >> s1 >> s2;
        if(s1=="") break;
        int l1=s1.length();
        int l2=s2.length();
        int dp[4010][4010];
        for(int i=0; i<l1; i++){
            if(s1[i]==s2[0]) dp[i][0]=1;
            else dp[i][0]=0;
        }
        for(int j=0; j<l2; j++){
            if(s1[0]==s2[j]) dp[0][j]=1;
            else dp[0][j]=0;
        }
        for(int i=1; i<l1; i++){
            for(int j=1; j<l2; j++){
                if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=0;
            }
        }
        int ans=0;
        for(int i=0; i<l1; i++){
            for(int j=0; j<l2; j++){
                ans=max(ans, dp[i][j]);
            }
        }
        cout << ans << "\n";
        
    }
    
    
    return 0;
}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<short> > dp(T.size() + 1, vector<short>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		int ret = 0;

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);

				if (T[i - 1] == S[j - 1])
				{
					dp[i][j]++;
				}
				else
				{
					dp[i][j] = 0;
				}

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

		printf("%d\n", ret);
	}

	return 0;
}