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		FILE_INPUT_DEFINE
#ifdef		FILE_INPUT_DEFINE
#include	<fstream>
#endif		// FILE_INPUT_DEFINE

#include	<iostream>
#include	<string>
#include	<algorithm>

using namespace std;

#define			MAX		1000
#define			ind(x)		((x) - 1)

int C[MAX][MAX];

int LCS(string &X, string &Y)
{
	int			Xlen = X.length();
	int			Ylen = Y.length();

	for (int i = 0; i <= Xlen; ++i)
	{
		C[i][0] = 0;
	}

	for (int i = 0; i <= Ylen; ++i)
	{
		C[0][i] = 0;
	}

	for (int i = 1; i <= Xlen; ++i)
	{
		for (int j = 1; j <= Ylen; ++j)
		{
			if (X[ind(i)] == Y[ind(j)])
			{
				C[i][j] = C[i - 1][j - 1] + 1;
			}
			else
			{
				C[i][j] = max(C[i - 1][j], C[i][j - 1]);
			}
		}
	}

	return (C[Xlen][Ylen]);
}

int main()
{
#ifdef		FILE_INPUT_DEFINE
	// input from txt
	std::ifstream in(R"(C:\Temp\input.txt)");
	std::cin.rdbuf(in.rdbuf());
#endif		// FILE_INPUT_DEFINE

	string	X, Y;
	int		n;

	cin >> n;
	cin.clear();
	cin.ignore();

	for (int i = 0; i < n; ++i)
	{
		getline(cin, X);
		getline(cin, Y);

		cout << LCS(X, Y) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

void solve() {
	string x, y;
	cin >> x >> y;
	int xlen = x.length();
	int ylen = y.length();
	int dp[155][155];
	dp[0][0] = 0;

	for (int i = 0; i <= xlen; i++) {
		for (int j = 0; j <= ylen; j++) {
			if (i == 0 || j == 0) {
				dp[i + 1][j + 1] = 0;
			}
			else if (x[i - 1] == y[j - 1]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	cout << dp[xlen + 1][ylen + 1] << endl;
}
int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)solve();
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j])
	dp[i][j] = dp[i-1][j - 1] + 1;
      else if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

  string X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  }

  return 0;
}

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

template<class T>
T myMin(const T& arg){
	return arg;
}
template<class F, class... S>
F myMin(const F& first, const S&... second){
	F m = myMin(second...);
	if (m > first){
		return first;
	}else{
		return m;
	}
}
int f(std::string::iterator str1, const std::string& str2, const std::vector<int>& vec){
	std::vector<int> new_v;
	new_v.push_back(vec[0] + 1);
	{
		auto v = vec.begin() + 1;
		for (auto i = str2.begin(); i != str2.end(); ++i, ++v){
			if (*i == *str1){
				new_v.push_back(*(v - 1));
			}else{
				new_v.push_back(myMin(*v + 1, new_v.back() + 1));
			}
		}
	}
	if (*(++str1) != '\0'){
		return f(str1, str2, new_v);
	}else{
		return new_v.back();
	}
}
int main(){
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i){
		std::string str1, str2;
		std::cin >> str1 >> str2;
		std::vector<int> vec;
    vec.push_back(0);
		for (int j = 0; j < str2.size(); ++j){
			vec.push_back(j);
		}
		std::cout << (str1.size() + str2.size() - f(str1.begin(), str2, vec)) / 2 << "\n";
	}
}

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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();
    cout << "### nMAXNX = (" << nMAXNX << ")" << endl;
    cout << "### nMAXNY = (" << nMAXNY << ")" << endl;

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

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

int main(){
    int q;
    std::string X,Y;
    std::cin>>q;

    int xy[1000][1000]={};
    
    for(int i=0;i<q;i++){
        std::cin>>X>>Y;
        //int xy[1001][1001]={};
        for(int j=1;j<=X.size();j++){
            for(int k=1;k<=Y.size();k++){
                if(X[j-1]==Y[k-1]){
                    xy[j][k]=xy[j-1][k-1]+1;
                }else{
                    xy[j][k]=std::max(xy[j][k-1],xy[j-1][k]);
                }
            }
        }
        std::cout<<xy[X.size()][Y.size()]<<"\n";
    }

return 0;
}