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 <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

short dp[4000][4000];
char s[4004], t[4004];

int main() {
    while (cin >> s >> t) {
        for (int j = 0; j < 4000; ++j) {
            fill(dp[j], dp[j] + 4000, 0);
        }

        int sLen = strlen(s);
        int tLen = strlen(t);

        short ret = 0;

        for (int j = 0; j < sLen; ++j) {
            for (int k = 0; k < tLen; ++k) {
                if (s[j] != t[k]) {
                    dp[j][k] = 0;
                } else if (j == 0 || k == 0) {
                    dp[j][k] = 1;
                } else {
                    dp[j][k] = dp[j-1][k-1] + 1;
                }

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

        cout << ret << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
char a[4001];
char b[4001];
short dp[4001][4001];
int max(int a,int b){return a>b?a:b;}
int main(){
	while(scanf(" %s",a)!=EOF){
	scanf(" %s",b);
	int n=strlen(a);
	int m=strlen(b);
	int i,j;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)dp[i][j]=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(a[i]==b[j])dp[i+1][j+1]=dp[i][j]+1;
		}
	}
	int ans=0;
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)ans=max(ans,dp[i][j]);
	printf("%d\n",ans);
	}
}

C++: #include<stdio.h>
#include<string.h>
typedef struct{
	int mx;
	int nx;
}data;
data d[4000][4000];
char a[4000],b[4000];
int i,j;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	while(scanf("%s",&a)!=EOF){
		scanf("%s",&b);
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++){
			d[i][j].nx=0;
			d[i][j].mx=0;
		}
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++){
				if(a[i]==b[j]){
					if(i>0&&j>0)d[i][j].nx=d[i-1][j-1].nx+1;
					else d[i][j].nx=1;
					if(i>0&&j>0)d[i][j].mx=max(d[i-1][j].mx,d[i][j-1].mx);
					else if(i>0)d[i][j].mx=d[i-1][0].mx;
					else if(j>0)d[i][j].mx=d[0][j-1].mx;
					d[i][j].mx=max(d[i][j].mx,d[i][j].nx);
				}
				else{
					d[i][j].nx=0;
					if(i>0&&j>0)d[i][j].mx=max(d[i-1][j].mx,d[i][j-1].mx);
					else if(i>0)d[i][j].mx=d[i-1][0].mx;
					else if(j>0)d[i][j].mx=d[0][j-1].mx;
				}
			}
		}
		/*for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j].mx);
			printf("\n");
		}
		printf("\n");
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j].nx);
			printf("\n");
		}*/
		printf("\n");
		printf("%d\n",d[strlen(a)-1][strlen(b)-1]);
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a,b;
int main(){
    while(cin >> a >> b){
        int x=0,y=0,t=1,tmp=0,ret=0,n=a.size(),m=b.size();
        while(x < n && y < m){
            if(a[x] == b[y]){
                tmp++;
                x++;
                y++;
            }else{
                ret = max(ret,tmp);
                tmp=0;
                t?x++:y++;
                t=1-t;
            }
        }
        cout << ret << endl;
    }
}

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();
		}
		cout<<a<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int cnt[4001][4001];
int main(){
  string str1,str2;
  while(cin >> str1){
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for(int i=1;i<=len1;i++){
      cnt[i][0] = 0;
    } 
    for(int i=1;i<=len2;i++){
      cnt[0][i] = 0;
    }
    int ret = 0;
    for(int i=1;i<=len1;i++){
      for(int j=1;j<=len2;j++){
	if(str1[i] == str2[j]){
	  cnt[i][j] = cnt[i-1][j-1] + 1;
	}
	else {
	  cnt[i][j] = 0;
	}
	ret = max(ret,cnt[i][j]);
      }
    }
    cout << ret << endl;
  }	
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double EPS = 1e-10;
const int mod=1e9+7;
int dp[4000][4000];
int main(){
  string s,t;
  while(cin>>s>>t){
    int ans=0;
    REP(i,s.size()){
      REP(j,t.size()){
        if(s[i]==t[j]){
          if(i==0||j==0)dp[i][j]=1;
          else dp[i][j]=dp[i-1][j-1]+1;
        }
        ans=max(ans,dp[i][j]);
      }
    }
    cout<<ans<<endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	string a,b;
	while(cin>>a>>b){
		int n=a.size(),m=b.size();
		vector<vector<int> >dp(n+1,vector<int>(m+1));
		loop(i,1,n+1)loop(j,1,m+1){
			if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
		}
		int ma=0;
		rep(i,n)rep(j,m)ma=max(ma,dp[i+1][j+1]);
		cout<<ma<<endl;
	}
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(cin){
		string s, t; int roop1=0, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s==/0){
		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= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						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;
	}
	
	return 0;
}