Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;


int lcs(string s, string t, int si, int ti, vector< vector<int> > memo) {
  
  if( si == -1 || ti == -1 ) {
    return 0;
  }
  if(memo[si][ti] != -1) {
    return memo[si][ti];
  }

  int res = 0;

  if( s[si] == t[ti] ) {
    res = lcs(s, t, si-1, ti-1, memo) + 1;
  } else {
    res = max( lcs(s, t, si-1, ti, memo), lcs(s, t, si, ti-1, memo) );
  }

  return memo[si][ti] = res;

}

int solve() {

  string s, t;
  cin >> s >> t;

  vector< vector<int> > memo( 1001,  vector<int>(1001, -1) );
  return lcs(s, t, s.size()-1, t.size()-1, memo );


  // dp[i][j] := s_1,...s_i と t_1,...t_j に対するLCSの長さ
  // s[i] == t[j] なら dp[i-1][j-1] + 1
  // s[i] != t[j] なら max( dp[i-1][j], dp[i][j-1] )
  // int dp[s.size()+1][t.size()+1];
  // fill(dp[0], dp[s.size()+1], 0);
  // for(int i = 0; i < s.size(); i++) {
  //   for(int j = 0; j < t.size(); 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]);
  //     }
  //   }
  // }

  // return dp[s.size()][t.size()];



}


int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  for(int i = 0; i < N; i++) {
    cout << solve() << "\n";
  }


  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#define MAX 1000
using namespace std;

int LCS(string X, string Y) {
    int i, j, maxl;
    int C[MAX+1][MAX+1];

    cin >> X >> Y;
    size_t X_len = X.length();
    size_t Y_len = Y.length();

    for (i=0; i<=X_len; i++) {
        for (j=0; j<=Y_len; j++) {
            if (i==0 || j==0) C[i][j]=0;
            else {
                if (X[i]==Y[j]) {
                    C[i][j]=C[i-1][j-1]+1;
                    maxl = max(C[i][j], maxl);
                } else C[i][j]=max(C[i-1][j], C[i][j]);
            }
        }
    }

    return maxl;
}

int main() {
    int n, i;
    string X, Y;
    
    cin >> n;
    for (i=0; i<n; i++) {
        cin >> X >> Y;
        cout << LCS(X, Y) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define MAX_N 1000

int solve(std::string s,std::string t){
        int dp[MAX_N][MAX_N];
        memset(dp,0,sizeof(dp));
        int n,m;
        n=s.size(),m=t.size();
        for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                        if(s[i]==t[j])
                                dp[i+1][j+1]=dp[i][j]+1;
                        else
                                dp[i+1][j+1]=std::max(dp[i][j+1],dp[i+1][j\
]);
                }
        }
        return dp[n][m];
}

int main(){
        int q;
        std::cin>>q;
        for(int i=0;i<q;i++){
                std::string s,t;
                std::cin >> s>>t;
                printf("%d\n",solve(s,t));
        }
        return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int INF = 1 << 29;
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define LEN 1000011
#define NIL -1
//_______


int slv(string &a, string &b)
{
   const int alen = a.size();
   const int blen = b.size();
   int dp[alen+1][blen+1] = {};
   a = ' ' + a;
   b = ' ' + b;
   int ret = 0;
   //reps(i, 0, alen)dp[0][i] = 0;
   //reps(i, 0, blen)dp[i][0] = 0;

   reps(i, 1, alen){
      reps(j, 1, blen){
         if(a[i] == b[j]){
            dp[i][j] = dp[i-1][j-1] + 1;
         } else {
            dp[i][j] = max(dp[i-1][j] , dp[i][j-1] );
         }
         chmax(ret, dp[i][j]);
      }
   }
   return(ret);
}

signed main()
{
   FAST();
   int N;
   cin >> N;
   rep(i, N){
      string a,b;
      cin >> a >> b;
      outl( slv(a, b) );
   }
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int dp[1002][1002];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s1,s2;
	while(n--){
		cin>>s1>>s2;
		REP(i,s1.size())dp[i][0] = 0;
		REP(i,s2.size())dp[0][i] = 0;
		FOR(i,1,s1.size()+1){
			FOR(j,1,s2.size()+1){
				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]);
			}
		}
		cout << dp[s1.size()][s2.size()] << endl;
	}
  return 0;
}

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

constexpr int MAX_XY = 1000;

int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;

void fill_dp(){
    for(int i = 1; i <= lx; ++i){
        for(int j = 1; j <= ly; ++j){
            if(sx[i] == sy[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
}

void solve(){
    fill_dp();
    std::cout << dp[lx][ly] << std::endl;
    return;
}

int main(){
    std::cin >> q;
    
    for(int i = 0; i < q; ++i){
        std::cin >> sx >> sy;
        lx = sx.size(), ly = sy.size();
        solve();
    }
    return 0;
}