Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int N;
  cin>>N;
  string S1,S2;
  for (int i=0; i<N; i++) {
    cin>>S1>>S2;
    int m=S1.length();
    int n=S2.length();
    S1=' '+S1;
    S2=' '+S2;
    int lcs[m+1][n+1];
    for (int i=1; i<=m; i++) {
      lcs[i][0]=0;
    }
    for (int j=1; j<=n; j++) {
      lcs[0][j]=0;
    }
    int maxl=0;
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (S1[i]==S2[j]) {
          lcs[i][j]=lcs[i-1][j-1]+1;
        }
        else {
          lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
        maxl=max(maxl,lcs[i][j]);
      }
    }
    cout<<maxl<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int q;
    cin >> q;

    int lcs[1010][1010];

    for (int i = 0; i < q; i++)
    {
        string x, y;
        cin >> x >> y;
        Fill(lcs, 0);
        for (int j = 1; j <= x.size(); j++)
        {
            for (int k = 1; k <= y.size(); k++)
            {
                if(x[j-1] == y[k-1]) lcs[j][k] = lcs[j-1][k-1] + 1;
                else lcs[j][k] = max(lcs[j-1][k], lcs[j][k-1]);
            }
        }
        cout << lcs[x.size()][y.size()] << endl;
    }

}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef pair<int, int> P;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};
const int INF = 1001001001;

int q;
vector<pair<string, string>> dataset;

int main() {
  cin >> q;
  dataset.resize(q);

  rep(i, q) {
    string x, y;
    cin >> x >> y;
    dataset[i] = make_pair(x, y);
  }

  vector<int> ans;

  for (auto&& data : dataset) {
    string x, y;
    tie(x, y) = data;

    vector<vector<int>> dp(x.size() + 1, vector<int>(y.size() + 1, 0));

    rep(i, x.size()) {
      rep(j, y.size()) {
        if (x[i] == y[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
      }
    }

    ans.push_back(dp[x.size()][y.size()]);
  }

  for (auto&& i : ans) {
    printf("%d\n", i);
  }
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>
#include<cassert>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX=1001;
const int INF=1<<29;

int dp[MAX][MAX];

int main(){

	int n;
	cin >> n;

	rep(i,n){
		string a,b;
		cin >> a >> b;
	
		fill_n((int *)dp,sizeof(dp)/sizeof(int),0);
		
		rep(i,a.size()+1){
			rep(j,b.size()+1){
				if(i==0||j==0) dp[i][j]=0;
				else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
				else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			}
		
		}

		cout << dp[a.size()][b.size()] << endl;
	
	}

}

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

int LCS(const char* s1, const char* s2){
	int i,j;
	int n1=strlen(s1);
	int n2=strlen(s2);
	int dp[n1+1][n2+1];
	for(i=0;i<=n1;i++)dp[i][0]=0;
	for(j=0;j<=n2;j++)dp[0][j]=0;
	for(i=1;i<=n1;i++){
		for(j=1;j<=n2;j++){
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	return dp[n1][n2];
}

int main(){
	int n;
	cin >> n;
	string s1;
	string s2;
	for (int i=0;i<n;i++){
		cin >> s1 >> s2;
		cout << LCS(s1.c_str(),s2.c_str());
		cout << endl;
	}
	return 0;
}

C++: def lcs(x, y)
  for i in range(1, len(x)):
    for j in range(1, lem(y)):
      if x[i] = y[j]:
        c[i][j] = c[i-1][j-1] + 1
      elif c[i-1][j]>c[i][j-1]:
        c[i][j] = c[i-1][j]
      else:
        c[i][j] = c[i][j-1]






q  = input()
x = [' ' for row in range(n+1)]
y = [' ' for row in range(n+1)]
c = [[' ' for col in range(1000)] for row in range(1000)]
for i in range(q):
  x = input()
  y = input()
  print lcs(x, y)

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int lcs(string X, string Y) {
  vector<vector<int>> c(2000, vector<int>(2000));
  int m = X.length();
  int n = Y.length();
  int maxl = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X.at(i - 1) == Y.at(j - 1)) {
        c.at(i).at(j) = c.at(i - 1).at(j - 1) + 1;
      } else {
        c.at(i).at(j) = max(c.at(i - 1).at(j), c.at(i).at(j - 1));
      }
      maxl = max(maxl, c.at(i).at(j));
    }
  }
  return maxl;
}

int main() {
  int q;
  cin >> q;

  vector<string> x(q);
  vector<string> y(q);
  rep(i, q) {
    cin >> x.at(i);
    cin >> y.at(i);
  }

  rep(i, q) { cout << lcs(x.at(i), y.at(i)) << endl; }
  return 0;
}