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 main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		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])
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int q;
  cin >> q;
  rep(i,q){
    string X,Y; cin >> X >> Y;
    vector<vector<int>> dp(1010,vector<int>(1010,0));
    rep(i,X.size())rep(j,Y.size()){
      if(X[i]==Y[j]){
        dp[i+1][j+1]=max({dp[i][j]+1,dp[i+1][j],dp[i][j+1]});
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
    cout << dp[X.size()][Y.size()] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#define lth 1000

using namespace std;

int main()
{
	int n, L[100][100], Lmax = 0, *save;
	string Xi[lth], Yi[lth];
	cin >> n;
	save = new int[n];
	for (int k = 0; k < n; k++)
	{
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}
	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}

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

int main(){
  int n;
  cin>>n;
  string str1,str2;
  vector<int> ans(n);
  cin.ignore();
  for(int i=0; i<n; i++){
    vector<char> a;
    vector<char> b;
    getline(cin,str1);
    for(int j=0; j<(int)str1.size(); j++){
      char ch=str1[j];
      a.push_back(ch);
    }
    getline(cin,str2);
    for(int j=0; j<(int)str2.size(); j++){
      char ch=str2[j];
      b.push_back(ch);
    }
  	int path[a.size()+1][b.size()+1];
  	for(int h=0; h<a.size()+1; h++){
  		for(int w=0; w<b.size()+1; w++){
  			if(h==0 || w==0){
  				path[h][w]=0;
  			}else{
  				int max=path[h-1][w];
  				if(max<path[h][w-1]) max=path[h][w-1];
  				if(a[h-1]==b[w-1] && max<path[h-1][w-1]+1){
  					max=path[h-1][w-1]+1;
  				}
  				path[h][w]=max;
  			}
  		}
  	}
  	ans[i]=path[a.size()][b.size()];
  }
  for(int i=0; i<n; i++){
  	cout<<ans[i]<<endl;
  }
  return 0;
}

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

int lcs(string X, string Y) {
  int cs[1001][1001];
  int m = X.size();
  int n = Y.size();
  int answer = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) cs[i][0] = 0;
  for (int j = 1; j <= n; j++) cs[0][j] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        cs[i][j] = cs[i - 1][j - 1] + 1;
      } else {
        cs[i][j] = max(cs[i - 1][j], cs[i][j - 1]);
      }
      answer = max(answer, cs[i][j]);
    }
  }

  return answer;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  string X, Y;

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

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin >> n;
    rep(i,n){
        string a,b;
        cin >> a >> b;
        int n1 = a.size();
        int n2 = b.size();
        int dp[n1+1][n2+1];
        rep(i,n1+1)rep(j,n2+1)dp[i][j] = 0;
        rep(i,n1)rep(j,n2){
            if(a[i+1] == b[j+1])dp[i+1][j+1] = min(dp[i+1][j],dp[i][j+1])+1;
            else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
        cout << dp[n1][n2] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second
int dp[1100][1100]; 

int main() {
	int n;
	string a, b;
	cin >> n;
	REP(z, n) {
		cin >> a >> b;
		REP(i, 1100) REP(j, 1100) dp[i][j] = 0;
		REP(i, a.length()) {
			REP(j, b.length()) {
				if (a[i] == b[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, max(dp[i][j + 1], dp[i + 1][j]));
				else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
		cout << dp[a.length()][b.length()] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algoritm>
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++) 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;
}

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