Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()+1][s2.size()+1];
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            if(i==0 || j==0){
                L[i][j]=0;
            }
            else if(s1[i] == s2[j]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()][s2.size()];
}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define MAX 1000
int dp[MAX+1][MAX+1];

int lcs(string X, string Y){
    int m = X.size();
    int n = Y.size();
    for(int i = 0; i <= m; i++) dp[i][0] = 0;
    for(int j = 0; j <= n; j++) dp[0][j] = 0;

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(X[i-1] == Y[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[m][n];
}

int main(){
    int q;
    cin >> q;

    string X, Y;

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

    return 0;

}

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