Go: package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

C++: //#include "aizu.h"
#include <iostream>
#include <string>
#include <vector>

//namespace alds1_10_c{
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(myMin(*v, *(v - 1), new_v.back()));
			}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<algorithm>
#include<vector>
#include<string>
#define NIL -1
using namespace std;

int count(const string& X, int i, const string Y, int j,
          vector<vector<int> >& MEMO){
    if (i >= X.size() || j >= Y.size()) return 0;
    if (MEMO[i][j] != NIL) return MEMO[i][j];
    int j_tmp = j;
    int saiyou = 0;
    while (j_tmp < Y.size()) {
        if (X[i] == Y[j_tmp]) {
            saiyou = count(X, i + 1, Y, j_tmp + 1, MEMO) + 1;
            break;
        };
        j_tmp++;
    }
    int next_X = count(X, i + 1, Y, j    , MEMO);
    // int next_Y = count(X, i    , Y, j + 1, MEMO);
    return MEMO[i][j] = max(saiyou, next_X);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        vector<vector<int> > MEMO(X.size(), vector<int>(Y.size(), NIL));
        cout << count(X, 0, Y, 0, MEMO) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string x,y;
int dp[1005][1005];
int lcs(string x,string y)
{

    int Max=-1;
    int n=x.size(),m=y.size();
    x=' '+x;
    y=' '+y;
    for(int i=1;i<=n;i++)dp[i][0]=0;        //边界条件就是从此开始的，所以要置为1，
    for(int i=1;i<=m;i++)dp[0][i]=0;        //不然循环查询的次数多了就会造成错误
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
         if(x[i]==y[j])dp[i][j]=dp[i-1][j-1]+1;
         else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
         //Max=max(Max,dp[i][j]);
        }
    return dp[n][m];
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
         cin>>x>>y;
        cout<<lcs(x,y)<<endl;
    }
    return 0;
}

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

signed main(void){
  
  int q; cin >> q;
  while(q--){
    string s,t; cin >> s >> t;
    int n = s.size(); int m = t.size();
    
    vector<vector<int>> dp(n+10,vector<int>(m+10,0));
    vector<vector<int>> M(n+10,vector<int>(m+10,0));
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){ 
        
        if(s[i] == t[j] ){ 
          dp[i+1][j+1] = max(dp[i][j]+1,max(dp[i][j+1],dp[i+1][j]));
        }
        else{
          dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
        
      }
    }
    
    cout << dp[n][m] << endl;
    
  }
  
  return 0;
}

C++: /*
** Longest Common Subsequence
*/

# include <cstdio>
# include <cstring>
# include <algorithm>
using namespace std;

const int MAX = 1000 + 5;

char s1[MAX], s2[MAX];
int c[MAX][MAX];

int lcs() {
    int m = strlen(s1+1);
    int n = strlen(s2+1);
    c[0][0] = 0;
    int maxl = 0;
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 0;
    }

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

    return maxl;
}

void solve() {
    int n;
    scanf("%d", &n);
    while (n--) {
        scanf("%s %s", s1+1, s2+1);
        printf("%d\n", lcs());
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
#define MAX 1000
using namespace std;
int lcs(string,string);

int main(){
  int i,n;
  string st1,st2;

  cin >> n;
  for(i = 0; i < n; i++){
    cin >> st1 >> st2;
    cout << lcs(st1,st2) << endl;
  }
  return 0;
}

int lcs(string st1,string st2){
  int preMax = 0;
  int m,n,i,j;
  int key[MAX+1][MAX+1];

  m = st1.size();
  n = st2.size();
  /**/
  st1 = ' '+st1;
  st2 = ' '+st2;
  for(i = 1; i <= m; i++){
    key[i][0] = 0;
  }
  for(j = 1; j <= n; j++){
    key[0][j] = 0;
  }
  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(st1[i] == st2[j]){
        key[i][j] = key[i-1][j-1]+1;
      }
      else{
        key[i][j] = max(key[i-1][j],key[i][j-1]);
      }
      preMax = max(preMax,key[i][j]);
    }
  }
  return preMax;
}