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 <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int results[1001][1001];

int lcs(string x, string y)
{
    // initialize
    for (int i = 0; i < 1001; ++i) {
        for (int j = 0; j < 1001; ++j)
            results[i][j] = 0;
    }

    int maxlcs = 0;
    for (int i = 1; i <= x.length(); ++i) {
        for (int j = 1; j <= y.length(); ++j) {
            if (x[i-1] == y[j-1])
                results[i][j] = results[i-1][j-1] + 1;
            else
                results[i][j] = max(results[i-1][j], results[i][j-1]);

            if (maxlcs < results[i][j])
                maxlcs = results[i][j];
        }
    }
    return maxlcs;
}

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

    vector<string> x(n);
    vector<string> y(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; ++i)
        cout << lcs(x[i], y[i]) << '\n';
}

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

int main() {
    int q;
    cin >> q;
    
    rep(i,q) {
        string X,Y;
        cin >> X >> Y;
        int lX=X.size(), lY=Y.size();
        vector<vector<int>> dp(lX+1, vector<int>(lY+1,0));

        rep(i,lX)
            rep(j,lY)
                if(X.at(i) == Y.at(j))
                    dp.at(i+1).at(j+1) = dp.at(i).at(j)+1;
                else
                    dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j), dp.at(i).at(j+1));

        cout << dp.at(lX).at(lY) << 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=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]);
            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 <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  for(i=1;i<=strlen(X);i++){
    for(j=1;j<=strlen(Y);j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }

  xlength=strlen(X);
  ylength=strlen(Y);
}
    

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

  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\n",count[][]);
    }*/

  return 0;
}

C++: #include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950

void C (string x, string y){
    int p = x.size() ;
    int q = y.size() ;
    vector<vector<int>> dp (p + 1 , vector<int> (q + 1)) ;
    rep(i, p){
        rep(j, q){
            if(x.at(i) == y.at(j)){
                dp[i+1][j+1] = dp[i][j] + 1 ;
            }
            else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]) ;
            }
        }
    }
    cout << dp[p][q] << endl;
}

int main() {
    int n ; 
    cin >> n ;
    vector<string> s (n) ;
    vector<string> t (n);
    rep(i, n){
        cin >> s[i] ;
        cin >> t[i] ;
    }
    rep(k, n){
        C(s[k], t[k])  ;
    }
}

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

int main()
{
  std::vector<std::string> x;
  std::vector<std::string> y;
  std::vector<std::string> z;

  int n;
  std::string str1;
  std::string str2;
  std::string str_z;
  std::cin>>n;
  if(n>150){
   std::cout<<"EEROR\n";
   }
  for(int k=0;k<n;k++){
    std::cin>>str1;
    x.push_back(str1);
    std::cin>>str2;
    y.push_back(str2);
  }
  /*for(int i=0;i<n;i++){
    for(int j=0;j<x[i].size();j++){
      std::cout<<x[i][j]<<":";
      if(j==x[i].size()-1){
	std::cout<<"\n";
      }
    }   
  } 
  for(int i=0;i<n;i++){
    for(int j=0;j<y[i].size();j++){
      std::cout<<y[i][j]<<":";
      if(j==y[i].size()-1){
	std::cout<<"\n";
      }
    }
  }
  std::cout<<x[0].size()<<" "<<y[0].size()<<"\n";
  std::cout<<x[0][2]<<"\n";
  */
  int count[n]={0};
  for(int i=0;i<n;i++){
    int xl=0,yl=0,tmp=0,judege=0;
    if(x[i].size()<=y[i].size()){
      while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(yl==y[i].size()){
	  yl=tmp;
	  xl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=yl;
	}else{
	  yl++;
	}
      }
    }else{
     while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(xl==x[i].size()){
	  xl=tmp;
	  yl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=xl;
	}else{
	  xl++;
	}
      } 

    }
  }
  for(int i=0;i<n;i++){
    std::cout<<count[i]<<"\n";
    /*for(int j=0;j<z.size();j++){
      std::cout<<z[j];
    } 
    std::cout<<"\n";
    */
  }


  return 0;
}