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<bits/stdc++.h>
using namespace std;
main(){
  string a,b;
  int asize;
  int bsize;
  int ans;
  string s;
  while(cin>>a>>b){
    //大きい文字列候補から調べていく
    asize=a.size();
    bsize=b.size();
    if(asize>=bsize){
      ans=bsize;
      bool next=true;
      while(ans>0&&next){
	for(int i=0;i<bsize-ans+1;i++){
	  s=b.substr(i,ans);
	  if(a.find(s,0)!=string::npos&&next){
	    cout<<ans<<endl;
	    next=false;
	  }
	}
	ans--;
      }
      if(next){
	cout<<0<<endl;
      }
    }
    else{
      ans=asize;
      bool next=true;
      while(ans>0&&next){
	for(int i=0;i<asize-ans+1;i++){
	  s=a.substr(i,ans);
	  if(b.find(s,0)!=string::npos&&next){
	    cout<<ans<<endl;
	    next=false;
	  }
	}
	ans--;
      }
      if(next){
	cout<<0<<endl;
      }
    }
  }
}

C++: #include <cstdio>
#include <string>

using namespace std;

string scan_string() {
    char input[4000];

    if (scanf("%s", input) == EOF) {
        return "";
    }

    return string(input);
}

int main() {
    while (1) {
        int i;
        int n;
        string str1;
        string str2 = "";
        int max_sum = 0;

        str1 = scan_string();
        if (str1 == string("")) return 0;

        for (i=0;i<str1.length();i++) {
            str2 += " ";
        }
        str2 += scan_string();

        n = str2.length();
        for (i=0;i<n;i++) {
            int j;
            int m;
            string str3 = str2.substr(i, n-i);
            int sum = 0;

            m = min(str1.length(), str3.length());
            for (j=0;j<m;j++) {
                if (str1[j] == str3[j]) {
                    sum++;
                } else {
                    if (max_sum < sum) max_sum = sum;
                    sum = 0;
                }
            }
            if (max_sum < sum) max_sum = sum;
        }

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

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int doubles, lengths, dat[8002], tmp[8002], rank_[8002];
bool compare_suffix(int i, int j) {
	if (dat[i] == dat[j]) {
		int ri = (i + doubles <= lengths ? dat[i + doubles] : -1);
		int rj = (j + doubles <= lengths ? dat[j + doubles] : -1);
		return ri < rj;
	}
	return dat[i] < dat[j];
}
vector<int> suffix_array(string S) {
	lengths = S.size();
	vector<int> arrays(lengths + 1);
	for (int i = 0; i <= lengths; i++) {
		arrays[i] = i;
		dat[i] = i < lengths ? S[i] : -1;
	}
	for (doubles = 1; doubles <= lengths; doubles <<= 1) {
		sort(arrays.begin(), arrays.begin() + lengths + 1, compare_suffix);
		tmp[arrays[0]] = 0;
		for (int i = 1; i <= lengths; i++) tmp[arrays[i]] = tmp[arrays[i - 1]] + (compare_suffix(arrays[i - 1], arrays[i]) ? 1 : 0);
		for (int i = 0; i <= lengths; i++) dat[i] = tmp[i];
	}
	return arrays;
}
vector<int> lcp(string s, vector<int> sa) {
	vector<int> ret; ret.resize(lengths + 1);
	for (int i = 0; i <= lengths; i++) rank_[sa[i]] = i;
	int h = 0; ret[0] = 0;
	for (int i = 0; i < lengths; i++) {
		int j = sa[rank_[i] - 1];
		if (h > 0) h--;
		for (; j + h < lengths && i + h < lengths; h++) {
			if (s[j + h] != s[i + h]) break;
		}
		ret[rank_[i] - 1] = h;
	}
	return ret;
}
string s, t; int sl;
int main() {
	while (cin >> s >> t) {
		sl = s.size();
		s += '$' + t;
		vector<int> v1 = suffix_array(s);
		vector<int> v2 = lcp(s, v1);
		int ret = 0;
		for (int i = 0; i < lengths; i++) {
			if ((v1[i] < sl) != (v1[i + 1] < sl)) {
				ret = max(ret, v2[i]);
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
        int roop1, roop2 = 0, save[10000], ans = 0;
	while(cin){
        string s, t; 
	cin >> s >> 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 <string>
#include <fstream>

using namespace std;

int check(string, string);

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

    int res = 0;

    for(int i = 0; i < str1.size(); i++){
      if(str1.size() > str2.size())
	rotate(str1.begin(), str1.begin() + 1, str1.end());
      else
	rotate(str1.begin(), str1.begin() + 1, str1.end());
      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
}

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{
      res = max(res, sn);
      sn = 0;
    }
  }
  return res;
}

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

using namespace std;

int main(){

	string s1,s2;
	while(cin >> s1 >> s2){
		int maxLength = 0;
		// ツづづェツつセツつッツつクツづァツつキツつゥ
		for(int i = -(int)s1.size(); i <= (int)s2.size(); i++){
			// ツ債。ツづ個つクツづァツつオツつスツ湘ウツ妥板づ個淞催オツづーツ渉堕つッツづゥ
			int cnt = 0;
			for(int j = 0; j < s1.size(); j++){
				if(i + j >= 0 && i + j < s2.size()){
					if(s1[j] == s2[i+j])
						cnt++;
					else{
						maxLength = max(maxLength,cnt);
						cnt=0;
					}
				}
			}
			maxLength = max(maxLength,cnt);
		}

		//for(int i = 0; i < str[0].size(); i++){
		//	for(int j = 0; j < str[1].size(); j++){
		//		if(str[0][i] == str[1][j]){
		//			int length = 1;
		//			for(int k = 1; k + i < str[0].size() && k + j < str[1].size(); k++){
		//				if(str[0][k+i] == str[1][k+j])
		//					length++;
		//				else
		//					break;
		//			}
		//			maxLength = max(maxLength,length);
		//		}
		//	}
		//}
		cout << maxLength << endl;
	}

	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] = max(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;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  string a,b;
  while(cin >> a >> b){
    int ans = 0;
    for(int i = 0; i < (int)a.size(); i++){
      int c = 0;
      int t = 0;
      for(int j = 0; j < (int)a.size() - i && j < (int)b.size(); j++){
	if(a[i+j] == b[j]){
	  c++;
	}else{
	  t = max(t,c);
	  c = 0;
	}
      }
      ans = max(t,ans);
    }
    cout << ans << endl;
  }
}