Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int lcs(string x, string y) {
    static int c[1001][1001];
    int m = x.size();
    int n = y.size();
    int max1 = 0;
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 0; 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]);
            max1 = max(max1, c[i][j]);
 
        }
    }
    return max1;
}
 
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;
}

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

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

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

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
int dp[1001][1001];
//?????????????????????
int n;
string x,y;
void solve(){
	cin >> n;
	REP(j,n){
	cin >> x >> y;
	memset(dp,0,1001*1001);
	int xn = x.size();
	int yn = y.size();
	REP(jj,xn+1){
		 REP(ii,yn+1){
			 if(jj <= 0 || ii <= 0){
				 dp[jj][ii] = 0 ;
			 }
			 else if(x[jj-1]==y[ii-1]) {
				 dp[jj][ii] = 1 + dp[jj-1][ii-1];
			 }
			 else{
				 dp[jj][ii] = max ( dp[jj-1][ii], dp[jj][ii-1] );
		   }
			 //cout << '('<<ii<<','<<jj<<')'<<dp[jj][ii]<<endl;
		 }

	}
	cout << dp[xn][yn]<<endl;
	}


}


int main(){
solve();
}

C++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

#define PB push_back
#define SZ(x) ((int)(x).size())

using namespace std;

typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<int> > VVi;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }

int n;
Vs vs, vt;

int main()
{
	cin >> n;
	REP(_i, n)
	{
		string s, t;
		cin >> s >> t;
		vs.PB(s);
		vt.PB(t);
	}

	REP(_i, n)
	{
		string& s = vs[_i];
		string& t = vt[_i];
		
		VVi dp(SZ(s) + 1, Vi(SZ(t) + 1, 0));

		REP(i, SZ(s))
			REP(j, SZ(t))
		{
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
			if (s[i] == t[j])
				chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		}

		cout << dp[SZ(s)][SZ(t)] << endl;
	}


}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int dp[1001][1001] = {};

int getLCS(string X, string Y)
{
    int m = 0;
    for (int i = 1; i <= X.size(); i++)
    {
        for (int j = 1; j <= Y.size(); j++)
        {
            dp[i][j] = X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]);
            m = max(m, dp[i][j]);
        }
    }
    return m;
}

int main()
{
    int q;
    string X, Y;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> X >> Y;
        cout << getLCS(X, Y) << "\n";
    }
    return 0;
}

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

using namespace std;
int n;

int main(void){
    // Your code here!
    string S, T;
    int dp[1001][1001];
    cin >> n;
    for(int c = 0; c < n; c++){
        cin >> S >> T;
        
        for(int i = 0; i <= S.size(); i++){
            dp[i][0] = 0;
        }
        for(int j = 0; j <= T.size(); j++){
            dp[0][j] = 0;
        }
        
        for(int i = 0; i < S.size(); i++){
            for(int j = 0; j < T.size(); j++){
                if(S[i]==T[j]) dp[i+1][j+1] = max({dp[i][j] + 1, 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[S.size()][T.size()] << endl;
    }
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[1001][1001];
  
  while (flag == 0)
  {
    if (x[xn] >= 97 && x[xn] <= 122)
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] >= 97 && y[yn] <= 122)
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 1; j++)
    {
      if (x[i - 1] == y[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 (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}