Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <iostream>
#include <string>
using namespace std;
static const int MAX = 1001;

void lcs(string X, string Y) {
	int dp[MAX][MAX];  
	int i,j;

	int xLength = X.size();
	int yLength = Y.size();


	// initialize dp[][]
	for (i = 1; i <= xLength; i++)
		dp[i][0] = 0;
	for (i = 1; i <= yLength; i++)
		dp[0][i] = 0;

	for (i = 1; i <= xLength; i++){
		for (j = 1; j <= yLength; j++){
			// Because the original string is 0-based , so subtracted from 1
			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]);
			}
		}
	}

	// testing code: print out the dp[][]
	// cout << "j";
	// for (j = 1; j <= yLength; j++)
	// 	cout << ' ' << j ;
	// cout << endl;
		

	// for (i = 1; i <= xLength; i++){
	// 	cout << i << '.';
	// 	for (j = 1; j <= yLength; j++){
	// 		cout << dp[i][j] << ' ';
	// 	}
	// 	cout << endl;
	// }

	cout << dp[xLength][yLength] << endl;
}

int main() {
	int n , i;
	string X, Y;

	cin >> n;
	for (i = 0 ; i < n; i++ ) {
		cin >> X;
		cin >> Y;
		lcs(X, Y);
	}

	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] = mx(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 <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>

int LCS(std::string s,std::string t){
    int n,m,c[1001][1001]={0};
    n=s.size();
    m=t.size();
    int maxlen=0;
    for(int i=1;i<=n;i++){
        c[i][0]=0; 
    }
    for(int i=1;i<=m;i++){
        c[0][i]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                c[i][j]=c[i-1][j-1]+1;
            }else{
                c[i][j]=std::max(c[i-1][j],c[i][j-1]);
            }
            maxlen=std::max(maxlen,c[i][j]);
        }
    }
    return maxlen;
}
int main(){
	int N;
    
    std::cin >> N;
    std::string s1,s2;
    for(int i=0;i<N;i++){
        std::cin >> s1 >> s2;
        std::cout << LCS(s1,s2) <<std::endl;
    }
    return 0;
}

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