Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int q;
    cin >> q;
    vector<int> ans(q, 0);
    for(int ind=0; ind<q; ind++){
        string x, y;
        cin >> x >> y;
        // dp[i][j] は、x の i 文字目までの部分列のうち、y の j 文字目でちょうど終了するものの長さの最大
        // 最後には max_j dp[x.size()-1][j] を見れば ok
        vector<vector<int>> dp(x.size(), vector<int>(y.size(), 0));
        // i=0 だけ別処理
        for(int j=0; j<y.size(); j++){
            if(x[0] == y[j]) dp[0][j] = 1;
        }
        for(int i=1; i<x.size(); i++){
            int l = 0;
            for(int j=0; j<y.size(); j++){
                if(x[i] == y[j]){
                    dp[i][j] = max(dp[i-1][j], l+1);
                }
                else{
                    dp[i][j] = dp[i-1][j];
                }
                l = max(l, dp[i-1][j]);
            }
        }

        for(int j=0; j<y.size(); j++){
            ans[ind] = max(ans[ind], dp[x.size()-1][j]);
        }
    }

    for(int i=0; i<q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int LCS(string A, string B)
{
    int s1 = A.size();
    int s2 = B.size();
    int X[s1 + 1][s2 + 2];
    for (int i = 0; i < s1+1; i++)
    {
        for (int j = 0; j < s2+1; j++)
        {
            if (i > 0 && j > 0)
            {
                if (A[i-1] == B[j-1])
                {
                    X[i][j] = max(X[i - 1][j - 1] + 1, max(X[i][j - 1], X[i - 1][j]));
                }
                else
                {
                    X[i][j] = max(X[i - 1][j], X[i][j - 1]);
                }
            }
            else
            {
                X[i][j] = 0;
            }
        }
    }
    int N = X[s1][s2];
    return N;
}
int main()
{
    int N;
    cin >> N;
    for(int i = 1; i < N + 1; i++){
        string A;
        string B;
        cin >> A;
        cin >> B;
        cout << LCS(A,B) << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int p[1001][1001]={0};
int main(){
int i,j,q,e,l,z,m,u,n;
char s[2001],c[2001];
cin>>q;
for(e=0;e<q;e++){
scanf("%s %s",s,c);
l=strlen(s);
z=strlen(c);

for(i=0;i<=l;i++){
	for(j=0;j<=z;j++){
		p[i][j]=0;
	}
}
for(i=1;i<=z;i++){
	for(j=1;j<=l;j++){
		if(c[i-1]==s[j-1]){
			m=0;
			for(u=0;u<i;u++){
				for(n=0;n<j;n++){
					if(m<p[n][u])m=p[n][u];
				}
			}
		p[j][i]=m+1;
		}
	p[j][i]=max(p[j][i],p[j-1][i]);
	}
}
for(i=1;i<=z;i++){
	for(j=i+1;j<=z;j++){
		if(p[l][i]>p[l][j]){
			m=p[l][i];
			p[l][i]=p[l][j];
			p[l][j]=m;
		}
	}
}
cout<<p[l][z]<<endl;
}
return 0;
}

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++){
    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(mxl, 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 << lcs8s1, s2) << endl;
  }
  return 0;
}