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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	int max = 0;
	for (int i = x_begin; X[i] != '\0'; i++) {
		for (int j = y_begin; Y[j] != '\0'; j++) {
			if (X[i] == Y[j]) {
				int v_lcs = lcs(i + 1, j + 1);
				if (v_lcs + 1 > max) {
					max = v_lcs + 1;
				}
			}
		}
	}
	return table_lcs[x_begin][y_begin] = max;

}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;
	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		Y = stringY.c_str();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

using namespace std;
const int N_MAX = 1000;
char x[N_MAX+10], y[N_MAX+10];
int dp[N_MAX][N_MAX];

void solve() {
  int i, j;
  scanf("%s", x);
  scanf("%s", y);
  int N = strlen(x);
  int M = strlen(y);
  //printf("N = %d M = %d", N, M);
  for (i = 0; i < N+1; i++) {
    dp[i][0] = 0;
  }
  for (j = 0; j < M+1; j++) {
    dp[0][j] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      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]);
      }
    }
  }
  printf("%d\n", dp[N][M]);
} 

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    solve();
  }
  return 0;
}

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

int dp[2000][2000];

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  while(n--){
    string sa, sb; cin >> sa >> sb;
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= sa.size(); i++){
      for(int j = 1; j <= sb.size(); j++){
        if(sa[i] == sb[j]){
          dp[i][j] = dp[i-1][j-1] + 1;
        }else{
          dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
      }
    }
    cout << dp[sa.size()][sb.size()] << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

short checkTable[1001][1001];

int tmp_max=0;


void calc(int index,char pattern[],char to_search[],int to_search_length){

	for(int i=to_search_length-1;i>=0;i--){
		if(to_search[i]==pattern[index]){
			checkTable[index][i]=1;
			if(pattern[index+1]!='\0' && i < to_search_length-1){
				checkTable[index][i] = checkTable[index+1][i+1] + checkTable[index][i];
			}
		}else{
			if(i != to_search_length-1){
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>checkTable[index][i+1])
							?checkTable[index+1][i]:checkTable[index][i+1];

				}else{
					checkTable[index][i]=(checkTable[index][i+1]>0)?checkTable[index][i+1]:0;
				}
			}else{
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>0)?checkTable[index+1][i]:0;
				}else{
					checkTable[index][i] = 0;
				}
			}
		}
		tmp_max = (tmp_max >= checkTable[index][i])?tmp_max:checkTable[index][i];
	}
}

int main(){

	int q,left_length,right_length;
	char left[1001],right[1001];

	scanf("%d",&q);

	for(int i=0;i<q;i++){
		left_length=0;
		right_length=0;
		scanf("%s %s",left,right);
		for(int k=0;left[k]!='\0';k++)left_length++;
		for(int k=0;right[k]!='\0';k++)right_length++;

		if(right_length>=left_length){

			for(int k=left_length-1;k>=0;k--)calc(k,left,right,right_length);
		}else{

			for(int k=right_length-1;k>=0;k--)calc(k,right,left,left_length);
		}
		printf("%d\n",tmp_max);
		tmp_max=0;
	}

    return 0;
}

C++: #include <iostream>
#define MAX 1010

int C[MAX][MAX];

int main() {
  int n;
  std::cin >> n;
  int answers[160];

  for(int m=0; m<n; ++m) {
    std::string X;
    std::string Y;
    std::cin >> X;
    std::cin >> Y;

    // initialize
    for(int k=0; k<MAX; ++k) {
      for(int j=0; j<MAX; ++j) C[k][j] = 0;
    }

    // lcs
    int xlen = X.size();
    int ylen = Y.size();

    for(int i=1; i<=xlen; ++i) {
      for(int j=1; j<=ylen; ++j) {
        if(X[i] == Y[j]) {
          C[i][j] = C[i-1][j-1] + 1;
        } else {
          C[i][j] = std::max(C[i-1][j], C[i][j-1]);
        }
      }
    }

    answers[m] = C[xlen][ylen];
  }

  for(int h=0; h<n; ++h) {
    std::cout << answers[h] << std::endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; j <= n; j++)c[0][j] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (X[i] == Y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}

		return maxl;
}

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

		return 0;
	}