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<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};

	int 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>
#include <string>
using namespace std;

int main(){
    cout << "????§?" << endl;
    string s,t;
    while(cin >> s >> t){
        s = " " + s;
        t = " " + t;
        int Len[4001][4001];
        for(int i=0; i<s.size(); i++){
            Len[i][0] = 0;
        }
        for(int i=1; i<=s.size(); i++){
            for(int j=1; j<=t.size(); j++){
                if(s[i]==t[j]) Len[i][j] = 1+Len[i-1][j-1];
                else Len[i][j] = 0;
            }
        }
        int an = 1;
        for(int i=0; i<s.size(); i++){
            for(int j=0; j<t.size(); j++){
                an = max(an, Len[i][j]);
            }
        }
        if(an==1) cout << 0 << endl;
        else cout << an << endl;
    }
    cout << "syuuryou" << endl;
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
bool find(string s, string key) {
	for (int i = 0; i < s.size() - key.size(); i++)if (s.substr(i, key.size()) == key)return true;
	return false;
}
int main() {
	string s, t;
	while (cin >> s >> t) {
		int ans = 0;
		int l = 0, r = 0;
		while (r < s.size()) {
			if (find(t, s.substr(l, r - l + 1))) {
				r++;
				if (r - l > ans)ans++;
			}
			else {
				l++;
				if (r < l)r++;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int left_length,right_length,max,tmp,left_start,left_end,right_start,right_end,k;
	char left[4001],right[4001];

	while(scanf("%s",left) != EOF){
		scanf("%s",right);

		for(left_length = 0;left[left_length] != '\0';left_length++);
		for(right_length = 0; right[right_length] != '\0';right_length++);

		max = 0;
		if(right_length > left_length){

			//left???????????¨right???????????????????????§
			for(right_end = 1;right_end <= left_length;right_end++){
				tmp = 0;
				for(left_start = left_length-right_end,k=0; k < right_end; k++){
					if(left[left_start+k] == right[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//left???????????¨right???????????????????????§
			for(right_end = left_length;right_end < right_length;right_end++){
				tmp = 0;
				for(right_start = right_end-left_length,k=0;right_start + k < right_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//left_end???0??????????????§
			for(left_end = left_length-1;left_end >= 1; left_end--){
				tmp = 0;
				for(right_start = right_length-left_end,k=0;k < left_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			printf("%d\n",max);

		}else{

			//right???????????¨left???????????????????????§
			for(left_end = 1;left_end <= right_length;left_end++){
				tmp = 0;
				for(right_start = right_length-left_end,k=0; k < left_end; k++){
					if(right[right_start+k] == left[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//right???????????¨left???????????????????????§
			for(left_end = right_length;left_end < left_length;left_end++){
				tmp = 0;
				for(left_start = left_end-right_length,k=0;left_start + k < left_end; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//right_end???0??????????????§
			for(right_end = right_length-1;right_end >= 1; right_end--){
				tmp = 0;
				for(left_start = left_length-right_end,k=0;left_start + k < left_length; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

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

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
int dp[5000][5000];
using namespace std;
int main(){
  string s,str;
  int ans = 0;
  while(cin >> s >> str){
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[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;
      }
    }
    cout << ans << endl;
  }
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int dp[4100][4100];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S,T;
  while(cin >> S){
    cin >> T;
    int N = S.size();
    int M = T.size();
    for(int i=0; i<N+1; i++){
      for(int j=0; j<M+1; j++){
        dp[i][j] = 0;
      }
    }
    int ans = 0;
    for(int i=0; i<N; i++){
      for(int j=0; j<M; j++){
        if(S[i] == T[j]){
          chmax(dp[i+1][j+1],dp[i][j]+1);
          chmax(ans,dp[i+1][j+1]);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}