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 f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	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])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

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

}

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

constexpr int MAX = 1000;
int dp[MAX+1][MAX+1];

int main() {
  int N;
  cin >> N;
  for (int n{}; n < N; ++n) {
    string s, t;
    cin >> s >> t;
    for (size_t i{}; i < s.length(); ++i) {
      for (size_t j{}; j < t.length(); ++j) {
        if (s[i] == t[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]);
      }
    }
    cout << dp[s.length()][t.length()] << endl;
  }
  return 0;
}