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 <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != EOF)
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw = 0){
    if(B[b] != EOF)
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1; i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[j-1])
        C[i][j] = C[i-1][j-1] + 1;
      else if(C[i-1][j] >= C[i][j-1])
        C[i][j] = C[i-1][j];
      else
        C[i][j] = C[i][j-1];
      if(ans < C[i][j])
        ans = C[i][j];
    }
  }
  
  return ans;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", &A);
    scanf("%s", &B);
    printf("%d\n", judge(A, B));
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
const int N_MAX = 1005;
char res[N_MAX][N_MAX];

int lcs(string X, string Y){
	int xLen = X.size();
	int yLen = Y.size();
	int maxRes=0;
	X=' '+X;
	Y=' '+Y;
	for(int i=1;i<=xLen;i++){
		for(int j=1;j<=yLen;j++){
			if(X[i]==Y[j]){
				res[i][j] = res[i-1][j-1]+1;
			}else if(res[i][j-1]>=res[i-1][j]){
				res[i][j] = res[i][j-1];
			}else{
				res[i][j] = res[i-1][j];
			}
			maxRes = (res[i][j]>maxRes)?res[i][j]:maxRes;
		}
	}
	return maxRes;
}

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

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

using namespace std;

int lcs[1001][1001];

int seek_lcs_body(const char* s1, int pos1, const char* s2, int pos2)
{
	if(s1[pos1] == s2[pos2]){
		return lcs[pos1][pos2] + 1;
	}
	else if(s1[pos1] != s2[pos2]){
		int max = lcs[pos1+1][pos2] > lcs[pos1][pos2+1]? lcs[pos1+1][pos2] : lcs[pos1][pos2+1];
		return max;
	}
	return 0;
}

int seek_lcs(const char* s1, const char* s2)
{
	int sz1=strlen(s1), sz2=strlen(s2);
	for(int i=1; i<=sz1; ++i){
		for (int j=1; j<=sz2; ++j){
			lcs[i][j] = seek_lcs_body(s1, i-1, s2, j-1);
		}
	}
	cout << lcs[sz1][sz2] << endl;
	return 0;
}

int main(){
	int q;
	scanf("%d",&q);

	for(int i=0; i<1001; ++i){
		lcs[i][0] = 0;
		lcs[0][i] = 0;
	}

	for(int i=0; i<q; ++i){
		string s1, s2;
		cin >> s1;
		cin >> s2;
		seek_lcs(s1.c_str(), s2.c_str());
	}
	return 0;
}

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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0, p = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			mat[i][0] = x[i] == y[0] ? true : false;
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			mat[0][i] = x[0] == y[i] ? true : false;
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				mat[i][j] = x[i] == y[j] ? true : false;
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
				if (a[i][j] > p) p = a[i][j];
			}
		}
		if (a[x.length() - 1][0] > p) p = a[x.length() - 1][0];
		if (a[0][y.length() - 1] > p) p = a[0][y.length() - 1];
		cout << p << endl;
	}


	return 0;
}

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

using namespace std;



int n;
string a, b;



int main(){
  cin >> n;
  while(n != 0){
    n = n -1;
    int longest[1000][1000];
    cin >> a;
    cin >> b;
    a = ' ' + a;
    b = ' ' + b;
    int mm = 0;
    
   
    for(int i = 1; i <= a.size(); ++i){
      for(int j = 1; j <= b.size(); ++j){
        if(j == 0 || i == 0){
          longest[i][j] = 0;
        }
        else if(a[i] == b[j]){
          longest[i][j] = 1 + longest[i-1][j - 1];
        }
        else{
          longest[i][j] = max(longest[i][j-1], longest[i-1][j]);
        }
        mm = max(mm, longest[i-1][j-1]);
      }
    }
    //cout << a[1] << endl;
    cout << mm << endl;
  }
}

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

int q;
int **len;
int common(string a,string b,int m,int n){
    if(m==0||n==0){
        return 0;
    }
    if(a[m-1]==b[n-1]){
        if(m>1&&n>1){
            if(len[m-2][n-2]!=-1)len[m-1][n-1]=len[m-2][n-2]+1;
            else len[m-1][n-1]=common(a.substr(0,m-1),b.substr(0,n-1),m-1,n-1)+1;
        }else{
            len[m-1][n-1]=1;
        }
    }
    else{
        int l1,l2;
        //?±?l1
        if(n>1){
            if(len[m-1][n-2]!=-1)l1=len[m-1][n-2];
            else l1=len[m-1][n-2]=common(a,b.substr(0,n-1),m,n-1);
        }else l1=0;
        if(m>1){
            if(len[m-2][n-1]!=-1)l2=len[m-2][n-1];
            else l2=len[m-2][n-1]=common(a.substr(0,m-1),b,m-1,n);
        }else l2=0;

        len[m-1][n-1]=max(l1,l2);
    }
    return len[m-1][n-1];
}

int main()
{
    cin>>q;
    int i;
    for(i=0;i<q;i++){
        string a,b;
        cin>>a>>b;
        int m=a.length();
        int n=b.length();
        len=new int*[m];
        int j;
        for(j=0;j<m;j++){
            len[j]=new int[n];
            memset(len[j],-1,n*sizeof(int));
        }
        cout<<common(a,b,m,n)<<endl;
    }
    return 0;
}

//int main(){
//    int **p=new int*[5];
//    p[1]=new int[5];
//    memset(p[1],-1,5*sizeof(int));
//    cout<<p[1][3]<<" "<<p[0][1];
//}