Go: package main

/*
最長共通部分列
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func larger(l, r int) int {
	if l > r {
		return l
	}
	return r
}

var memo [1001][1001]int

func countLCS(x, y string) int {
	x = " " + x
	y = " " + y
	max := 0
	for xi := 1; xi < len(x); xi++ {
		for yi := 1; yi < len(y); yi++ {
			if x[xi] == y[yi] {
				memo[xi][yi] = memo[xi-1][yi-1] + 1
			} else {
				memo[xi][yi] = larger(memo[xi-1][yi], memo[xi][yi-1])
			}
			max = larger(max, memo[xi][yi])
		}
	}
	return max
}

func main() {
	scanner := makeScanner(1024)
	q := eGetInt(scanner)
	for i := 0; i < q; i++ {
		x := eGetLine(scanner)
		y := eGetLine(scanner)
		fmt.Println(countLCS(x, y))
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	buf.WriteString("[")
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = ", "
	}
	buf.WriteString("]")
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func min(a []int) int {
	m := a[0]
	for _, v := range a {
		if v < m {
			m = v
		}
	}
	return m
}

func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}
func find(n int, a ints) int {
	for i, v := range a {
		if n == v {
			return i
		}
	}
	return -1
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
#define UNDEFCHAN -1
#define SUPL 1002
#define MISERU(name,value) cout<<name<<": "<<value<<endl;

int xl,yl;
char xs[SUPL],ys[SUPL];
int rss[SUPL][SUPL];

int r(int xi, int yi){
	if (rss[xi][yi]!=UNDEFCHAN) return rss[xi][yi];
	int re;
	if(xi==0) re=0;
	else if(yi==0) re=0;
	else if(xs[xi-1]==ys[yi-1]) re=r(xi-1,yi-1)+1;
	else re=max(r(xi-1,yi),r(xi,yi-1));
	rss[xi][yi]=re;
	return re;
}

int solve(){
	REP(xi,xl+1) REP(yi,yl+1) rss[xi][yi]=UNDEFCHAN;
	return r(xl,yl);
}

int main(){
	int ol;
	cin>>ol;
	REP(oi,ol){
		cin>>xs;
		cin>>ys;
		xl=strlen(xs);
		yl=strlen(ys);
		cout<<solve()<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int max(int x, int y){
	return (x < y) ? y : x;
}

int get_lcs_len(char X[1000], char Y[1000]){
	int x_len=0, y_len=0;

	for(; 'a'<=X[x_len] && X[x_len]<='z'; x_len++);
	for(; 'a'<=Y[y_len] && Y[y_len]<='z'; y_len++);
	for(; 'A'<=X[x_len] && X[x_len]<='Z'; x_len++);
	for(; 'A'<=Y[y_len] && Y[y_len]<='Z'; y_len++);

	int dp[y_len+1][x_len+1]={};
	int result = 0;

	for(int i=1; i<=y_len; i++){
		for(int j=1; j<=x_len; j++){
			if(X[j-1] == Y[i-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
			result = max(result, dp[i][j]);
		}
	}

	return result;
}

int main(){
	int q;
	char X[1000], Y[1000];

	cin >> q;

	int results[q];

	for(int i=0; i<q; i++){
		cin >> X >> Y;
		results[i] = get_lcs_len(X, Y);
	}

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

	return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define N (1000 + 10)

#define max(a, b) (a < b ? b : a)

int dp[N][N];

int LCS(char a[], char b[]){
  int tmp;
  
  const int a_size = strlen(a); // last one is '\n'
  const int b_size = strlen(b);
  int i, j;

  memset(dp, 0, sizeof(dp));

  for (i = 1; i < a_size + 1; ++i) {
    for (j = 1; j < b_size + 1; ++j){
      if (a[i - 1] == b[j - 1]){
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
      else{
	dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
      }
    }
  }

  return dp[a_size][b_size];
}

int main(void){
  int n, i;
  char a[N], b[N];

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s",a);
    scanf("%s",b);
    printf("%d\n", LCS(a,b));
  }
  return 0;
}

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

using namespace std;

int lcs(string s1, string s2) {
    int c[1005][1005];
    int m = s1.length();
    int n = s2.length();
    s1 = " " + s1;
    s2 = " " + s2;
    int max1=0;
    for (int i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 0; 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-1][j],c[i][j-1]);
            }
            max1=max(max1,c[i][j]);
        }
    }
    return max1;
}

int main() {
    int q;
    cin >> q;
    string s1, s2;
    for (int k = 0; k < q; k++) {
        cin >> s1;
        cin >> s2;
        cout<<lcs(s1,s2)<<endl;
    }

    return 0;
}

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

#define N 1000

int lsc(string x,string y){
    int c[N+1][N+1];
    int m=x.size();
    int n=y.size();
    int maxl=0;

    for (int i = 1; i <=m; ++i) {
        c[i][0]=0;
    }
    for (int j = 1; j <=n ; ++j) {
        c[0][j]=0;
    }
    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(maxl,c[i][j]);
        }
    }

    return maxl;
}

using namespace std;

int main() {
    string x,y;
    int n;
    cin>>n;
    for (int i = 0; i <n ; ++i) {
        cin>>x>>y;
        cout<<lsc(x,y)<<endl;
    }
    return 0;
}

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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

int q;
string s, t;
int dp[1010][1010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> q;
	rep(_, q) {
		cin >> s >> t;
		int n = s.size(), m = t.size();
		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]);
				}
			}
		}
		cout << dp[n][m] << endl;
	}
	return 0;
}