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++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s",a)!=EOF)
	{

		scanf("%s",b);
		memset(dp,0,sizeof(0));
		
		int as=strlen(a); int bs=strlen(b);
		int ret=0;
		for(int i=1;i<=as;i++)
		{
			for(int j=1;j<=bs;j++)
			{
				if(a[i-1]==b[j-1]) dp[i][j]=max(max(dp[i][j-1],dp[i][j]),max(dp[i-1][j-1]+1,dp[i-1][j]));
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

#define MAX_S 4000
#define MAX_T 4000
template<typename T> int longest_common_substring(T s,T t){
    int lens=s.size(), lent=t.size();
    static int dp[MAX_S+1][MAX_T+1];
    memset(dp,0,sizeof(dp));
    
    int maxi=0;
    
    rep(i,s.size()){
        rep(j,t.size()){
            if(s[i]==t[j])  dp[i+1][j+1] = dp[i][j]+1;
            else            dp[i+1][j+1] = 0;
            maxi = max(maxi,dp[i+1][j+1]);
        }
    }
    
    return maxi;
}


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

C++: #include <iostream>
#include <cstring>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define LL long long 
const int INF = 1145141919;

int dp[4002][4002];

int main(){
	string s1, s2;
	while (cin >> s1){
		cin >> s2;
		int ans = 0;
		memset (dp, 0, sizeof(dp));
		REP (i, s1.size()){
			REP (j, s2.size()){
				if (s1[i] == s2[j]){
					dp[i+1][j+1] = dp[i][j] + 1;
					ans = max (ans, dp[i+1][j+1]);
				}
			}
		}
		cout << ans << endl;
	}	
}

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

using namespace std;

int main() {
    string s1, s2;
    while(cin >> s1 >> s2) {
        vector<vector<int> > dp(s1.size(), vector<int>(s2.size(), 0));

        int ans = 0;
        for(int i = 0; i < s1.size(); ++i) {
            for(int j = 0; j < s2.size(); ++j) {
                if(s1[i] == s2[j]) {
                    if(i > 0 && j > 0) dp[i][j] = dp[i-1][j-1]+1;
                    else dp[i][j] = 1;
                }
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

string str1;
string str2;
int solve(){
    int count=0;
    int m=0;
    int theta=0;
    int limit1;
    int limit2;
    int limit;
    limit1 = str1.size();
    limit2 = str2.size();
    for(int i=0;i<limit1;i++){
        limit = limit1-i;
        for(int j=0;j<limit;j++){
            theta++;
            if(str1[j+i] == str2[j]){
                count++;
            }else{
                m = max(m, count);
                count = 0;
            }
        }
        count = 0;
    }
    count = 0;
    for(int i=1;i<limit2;i++){
        limit = limit1+i<limit2 ? limit1+i : limit2;
        for(int j=i;j<limit;j++){
            theta++;
            if(str1[j-i] == str2[j]){
                count++;
            }else{
                m = max(m, count);
                count = 0;
            }
        }
        count = 0;
    }
    cout << theta << endl;
    return m;
}
int main(){
    string temp;
    while(cin >> str1 >> str2){
        if(str1.size() > str2.size()){
            temp = str1;
            str1 = str2;
            str2 = temp;
        }
        cout << solve() << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
	string a, b;
	while (cin >> a >> b) {
		int MAX = 0;
		for (int i = 0; i < a.size(); i++) {
			int c = 0;
			for (int j = 0; j < b.size(); j++) {
				if (i+j < a.size()) {
					if (a[i+j] == b[j]) {
						c++;
					} else {
						MAX = max(MAX, c);
						c = 0;
					}
				} else {
					MAX = max(MAX, c);
					break;
				}
			}
		}
		for (int i = 0; i < b.size(); i++) {
			int c = 0;
			for (int j = 0; j < a.size(); j++) {
				if (i+j < b.size()) {
					if (b[i+j] == a[j]) {
						c++;
					} else {
						MAX = max(MAX, c);
						c = 0;
					}
				} else {
					MAX = max(MAX, c);
					break;
				}
			}
		}
		cout <<MAX << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
int ans = 0;

int main()
{
  while(true){
    string s, t;
    cin >> s;
    if(!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int check(string, string);

int main()
{
  //ifstream ifs("data.txt");
  string str1, str2;
  while( cin >> str1 >> str2 ){

    int res = 0;

    for(int i = 0; i < str1.size(); i++){
      rotate(str1.begin(), str1.begin() + 1, str1.end());

      res = max(res, check(str1, str2));
    }

    for(int i = 0; i < str2.size(); i++){
	rotate(str2.begin(), str2.begin() + 1, str2.end());

      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
  //ifs.close();
}

int check(string str1, string str2)
{
  int sn = 0, res = 0;
  for(int i = 0; i < min(str1.size(), str2.size()); i++){
    if(str1[i] == str2[i]){
      sn++;
    }else{
      sn = 0;
    }
    res = max(res, sn);
  }
  return res;
}

C++: #include<bits/stdc++.h>
#define lld long long int
#define str string


using namespace std;

lld f();
lld ster,leg,leg2,ans=0,ans2=0;

str moji,moji2,cut;

int main(){

    cin >> moji >> moji2;
    leg=moji.size();
    leg2=moji2.size();

    cout << f() << endl;

return 0;
}

lld f(){
    for(int a=0;a<leg;a++){
            for(int b=1;b<leg-a;b++){
        cut = moji.substr(a,b);
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    }
    return ans2;
}