Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define L 1000

int LCSLength(char *X, char *Y){
  int m = strlen(X), n = strlen(Y);
  int i,j;
  int c[m+1][n+1];

  for(i=1; i<=m; i++) c[i][0] = 0;
  for(j=0; j<=n; j++) c[0][j] = 0;

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

  return c[i-1][j-1];
}

int main(void){
  int q,i,j;
  int LCS[MAX];
  char X[MAX][L], Y[MAX][L];

  // input & calculate
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%s", &X[i]);
    scanf("%s", &Y[i]);
    LCS[i] = LCSLength(X[i],Y[i]);
  }

  // output
  for(i=0; i<q; i++) printf("%d\n", LCS[i]);

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int q;
int dp[1100][1100];

int main(){
  cin >> q;
  rep(k, q){
    string x, y;
    cin >> x >> y;
    int n = x.size();
    int m = y.size();

    memset(dp, 0, sizeof(dp));
    rep(i, n){
      rep(j, m){
        if(x[i] == y[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
        else{
          chmax(dp[i+1][j+1], dp[i][j+1]);
          chmax(dp[i+1][j+1], dp[i+1][j]);
        }
      }
    }

    cout << dp[n][m] << endl;
  }

  return 0;
}

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

constexpr int MAX = 1000;
char ls[MAX];
char rs[MAX];
int table[MAX + 1][MAX + 1];


void calc_lcs() {
    scanf("%s", ls);
    scanf("%s", rs);
    int l_len = int(strlen(ls));
    int r_len = int(strlen(rs));
    for (int i = 0; i < l_len; i++) {
        table[i][0] = 0;
    }
    for (int i = 0; i < r_len; i++) {
        table[0][i] = 0;
    }

    for (int l_i = 1; l_i < l_len + 1; l_i++) {
        for (int r_i = 1; r_i < r_len + 1; r_i++) {
            if (ls[l_i - 1] == rs[r_i - 1]) {
                table[l_i][r_i] = table[l_i - 1][r_i - 1] + 1;
            } else {
                table[l_i][r_i] = std::max(table[l_i][r_i - 1], table[l_i - 1][r_i]);
            }
        }
    }
    std::cout << table[l_len][r_len] << std::endl;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        calc_lcs();
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int dp[1002][1002];

int main(){
	int n;
	cin >> n;
	int x, y;
	string X, Y;
	r(k, n){
		cin >> X >> Y;
		x = X.size();
		y = Y.size();
		X = ' ' + X;
		Y = ' ' + Y;

		r(i, x+1)
			r(j, y+1)
				dp[i][j] = 0;

		for (int i = 1; i <= x; i++) {
			for (int j = 1; j <= y; j++) {
				if (X[i] == Y[j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}

		cout << dp[x][y] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int q;cin>>q;
    vstr x(q),y(q);
    rep(i,q)cin>>x[i]>>y[i];
    vin ans(q);
    rep(i,q){
        int sx=x[i].size();
        int sy=y[i].size();
        vvin dp(sx+1,vin(sy+1,0));
        rep(j,sx){
            rep(k,sy){
                if(x[i][j]==y[i][k])dp[j+1][k+1]=max(dp[j][k]+1,max(dp[j+1][k],dp[j][k+1]));
                else dp[j+1][k+1]=max(dp[j+1][k],dp[j][k+1]);
            }
        }
        ans[i]=dp[sx][sy];
    }
    rep(i,q)cout<<ans[i]<<endl;
}

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

C++: #include <bits/stdc++.h>

#define NIL -1
#define INF 1000000001

using namespace std;


int main(){
    int num_dataset;
    char temp[1000];
    scanf("%d",&num_dataset);
    int numSubSeq[1001][1001];
    for(int i = 0;i < 1001;i++) numSubSeq[i][0] = 0; 
    for(int i = 0;i < 1001;i++) numSubSeq[0][i] = 0;

    for(int i = 0;i < num_dataset;i++){
        scanf("%s",temp);
        string str_A = temp;
        int size_A = (int)str_A.size();
        str_A = ' ' + str_A;
  
        scanf("%s",temp);
        string str_B = temp;
        int size_B = (int)str_B.size();
        str_B = ' ' + str_B;
     
        for(int j = 1;j <= size_A;j++){
            for(int k = 1;k <= size_B;k++){    
                if(str_A[j] == str_B[k]){
                    numSubSeq[j][k] = numSubSeq[j-1][k-1] + 1;
                }else{
                    numSubSeq[j][k] = max(numSubSeq[j-1][k],numSubSeq[j][k-1]);
                }
            }
        }
        printf("%d\n",numSubSeq[size_A][size_B]);
    }
    return 0;
}