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++: 
// @snippet<sh19910711/contest:headers.cpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <limits>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

// @snippet<sh19910711/contest:solution/define_classes.cpp>
namespace solution {
  class Solution;
  class Solver;
  class Storages;
}

// @snippet<sh19910711/contest:solution/interface.cpp>
namespace solution {
  class SolutionInterface {
  public:
    virtual ~SolutionInterface() {};
    virtual int run() = 0;
    
  protected:
    SolutionInterface() {}
    virtual void pre_calc() {}
    virtual bool action() = 0;
    virtual void init() {};
    virtual bool input( Storages& s ) { return false; };
    virtual void output( const Storages& s ) const {};
    virtual void before_action( const int& test_no ) const {}
    virtual void after_action( const int& test_no ) const {}
  };
}

// @snippet<sh19910711/contest:solution/solution-base.cpp>
namespace solution {
  class SolutionBase: public SolutionInterface {
  public:
    virtual ~SolutionBase() {}
    virtual int run() {
      this->pre_calc();
      for (;;) {
        this->before_action(-1);
        if ( ! this->action() ) { this->after_action(-1); break; }
        this->after_action(-1);
      };
      return 0;
    }
  protected:
    SolutionBase() {}
  };
}

// @snippet<sh19910711/contest:text/suffix_array.cpp>
namespace text {
  // SuffixArrayの実装
  class SuffixArray {
  public:
    typedef std::vector<int> VI;
    std::string s;
    int n, k;
    VI sa, rank, height;
    void build() {
      int maxlen = n;
      for ( int i = 0; i < n; ++ i ) rank[i] = s[i], maxlen = std::max( maxlen, s[i] + 1 );
      VI cnt(maxlen, 0);
      for ( int i = 0; i < n; ++ i ) cnt[rank[i]] ++;
      for ( int i = 1; i < maxlen; ++ i ) cnt[i] += cnt[i-1];
      for ( int i = 0; i < n; ++ i ) sa[--cnt[rank[i]]] = i;
      for ( k = 1; k < n; k *= 2 ) {
        VI r = rank;
        rank[sa[0]] = 0;
        for ( int i = 1; i < n; ++ i ) {
          int s1 = sa[i-1], s2 = sa[i];
          rank[s2] = r[s1] == r[s2] && std::max( s1, s2 ) + k < n && r[s1+k/2] == r[s2+k/2] ? rank[s1] : i;
        }
        for ( int i = 0; i < n; ++ i ) cnt[i] = i;
        VI s = sa;
        for ( int i = 0; i < n; ++ i ) {
          int s1 = s[i] - k;
          if ( s1 >= 0 ) sa[cnt[rank[s1]]++] = s1;
        }
      }
    }
    SuffixArray() { init(""); }
    SuffixArray( const std::string& s_ ) { init(s_); }
    void init( const std::string& s_ ) {
      s = s_; n = s.size(); sa.resize(n); rank.resize(n+1);height.resize(std::max(0,n-1));
    }
    VI::iterator begin() { return sa.begin(); }
    VI::iterator end() { return sa.end(); }
    int& operator []( int k ) { return sa[k]; }
    int size() { return n; }
    bool find( const std::string& key ) const {
      int lb = 0, ub = n;
      while ( ub - lb > 1 ) {
        int mid = ( lb + ub ) / 2;
        std::string t = s.substr( sa[mid] );
        if ( t.substr( 0, key.size() ) == key ) return true;
        else if ( t < key ) lb = mid;
        else ub = mid;
      }
      return false;
    }
    
    int lcp( int x, int y ) {
      int l = n - std::min( x, y );
      for ( int i = 0; i < l; ++ i ) if ( s[x+i] != s[y+i] ) return i;
      return l;
    }
    
    void buildHeight() {
      int h = 0;
      for ( int i = 0; i < n; ++ i ) {
        int j = rank[i];
        if ( j == n - 1 ) { h = 0; continue; }
        int k = sa[j+1];
        if ( h > 0 ) h = h - 1 + lcp( i + h - 1, k + h - 1 );
        else h = lcp( i, k );
        height[j] = h;
      }
    }
  };
}

// @snippet<sh19910711/contest:solution/typedef.cpp>
namespace solution {
  typedef std::istringstream ISS;
  typedef std::ostringstream OSS;
  typedef long long Int;
  typedef long double Double;
  typedef std::string String;
  
}

// @snippet<sh19910711/contest:solution/namespace-area.cpp>
namespace solution {
  // namespaces, types
  using namespace std;
  
}

// @snippet<sh19910711/contest:solution/consts-area.cpp>
namespace solution {
  // constant vars
  
  
}

// @snippet<sh19910711/contest:solution/storages-area.cpp>
namespace solution {
  typedef text::SuffixArray SuffixArray;

  // storages
  class Storages {
  public:
    String A;
    String B;
    SuffixArray SA;

    Int result;
  };
  
  Storages global_storages;
}

// @snippet<sh19910711/contest:solution/solver-area.cpp>
namespace solution {
  class Solver {
  public:
    void solve( Storages& s ) {
      init_suffix_array(s.A, s.SA);
      s.result = find_max_length(s.SA, s.B);
    }

  protected:
    static void init_suffix_array( const String& s, SuffixArray& sa ) {
      sa.init(s);
      sa.build();
    }

    static Int find_max_length( const SuffixArray& sa, const String& s ) {
      Int len = 0;
      int n = s.size();
      for ( int i = 0; i + len < n; ) {
        if ( sa.find(s.substr(i, len + 1)) ) {
          len ++;
        } else {
          i ++;
        }
      }
      return len;
    }
    
  };
}

// @snippet<sh19910711/contest:solution/solution.cpp>
namespace solution {
  class Solution: public SolutionBase {
  public:
    Solution() {}
    Solution(Storages* p): storages(p) {}
    
  protected:
    virtual bool action() {
      this->init();
      if ( ! this->input(*this->storages) )
        return false;
      solver.solve(*this->storages);
      this->output(*this->storages);
      return true;
    }

    bool input( Storages& s ) {
      return std::cin >> s.A >> s.B;
    }

    void output( const Storages& s ) const {
      std::cout << s.result << std::endl;
    }
    
  private:
    Solver solver;
    Storages* storages;
  };
}

// @snippet<sh19910711/contest:main.cpp>
#ifndef __MY_UNIT_TEST__
int main() {
  std::cin.sync_with_stdio(false);
  return solution::Solution(&solution::global_storages).run();
}
#endif

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