Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int q; cin >> q;
  vector<int> ans(q);
  rep(k, q) {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    rep(i, n) rep(j, m) {
      if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
    ans[k] = dp[n][m];
  }
  for(auto x : ans) cout << x << endl;
}

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

int dp[1010][1010];

int LCS(string s1, string s2)
{
	s1 = ' ' + s1;
	s2 = ' ' + s2;
	int maxl = 0;
	for(int i = 1; i <= s1.length(); ++ i)
	{
		for(int j = 1; j <= s2.length(); ++ j)
		{
			if(s1[i] == s2[j])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
			maxl = max(maxl, dp[i][j]);
		}
	}
	
	return dp[s1.length()-1][s2.length()-1];
}

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

C++: leng :: Int
leng = 1001

getPos :: Int -> Int -> Int
getPos y x = y * leng + x

lcs :: String -> String -> Int -> Int
lcs in1 in2 = (map lcs_func [0 ..] !!)
    where
      lcs_func n
          | (length in1) == 1 || (length in2) == 1 = if (head in1) == (head in2) then 1 else 0
          | (head in1) == (head in2) = (lcs (tail in1) (tail in2) (getUpLeft n)) + 1
          | otherwise = max (lcs (tail in1) in2 (getUp n)) (lcs in1 (tail in2) (getLeft n))
      getUp n = n - leng
      getLeft n = n - 1
      getUpLeft n = n - leng - 1

solve :: String -> String -> Int
solve in1 in2 = lcs in1 in2 (getPos ((length in1) - 1) ((length in2) - 1))

input :: Int -> IO ()
input n
    | n == 0 = return ()
    | otherwise = do
  str1 <- getLine
  str2 <- getLine
  putStrLn $ show $ solve str1 str2
  input $ n-1
                         

main :: IO()
main = do
  n <- readLn
  input n

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

typedef long long ll;
#define inf 1e9+7

int dp[1001][1001];
char x[1001],y[1001];

void init(){
    for(int i=0;i<1001;i++){
        dp[0][i]=0;
        dp[i][0]=0;
    }
}

void solve(int sn, int tn){
    for(int i=1;i<=sn;i++){
        for(int j=1;j<=tn;j++){
            if(x[i-1]==y[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s,t;
    for(int i=0;i<n;i++){
        init();
        cin >> s >> t;
        int sn=s.size();
        int tn=t.size();
        for(int j=0;j<sn;j++){
            x[j]=s[j];
        }
        for(int j=0;j<tn;j++){
            y[j]=t[j];
        }

        solve(sn, tn);
        cout << dp[sn][tn] << endl;
    }

}