Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	lenX, lenY := len(strX), len(strY)
	memo := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		memo[i] = make([]int, lenY+1)
	}

	lcs := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if strX[i-1] == strY[j-1] {
				memo[i][j] = memo[i-1][j-1] + 1
			} else {
				if memo[i-1][j] > memo[i][j-1] {
					memo[i][j] = memo[i-1][j]
				} else {
					memo[i][j] = memo[i][j-1]
				}
			}
			if memo[i][j] > lcs {
				lcs = memo[i][j]
			}
		}
	}
	return lcs
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int LCS(std::string str1, std::string str2, int i, int j){
  if(str1[i] == str2[j]){
    return 1;
  }
  else{
    return 0;
  }
}

int max(int a, int b, int c){
  int m = a;
  if(b > m){
    m = b;
  }
  if(c > m){
    m = c;
  }
  return m;
}

int main(){
  int q;
  std::cin >> q;
  //int ans[q];
  std::string str1, str2;
  for(int z=0; z<q; z++){
    std::cin >> str1 >> str2;
    int l1 = str1.size();
    int l2 = str2.size();
    int DP[l1+1][l2+1] = {};

    for(int i=1; i<=l1; i++){
      for(int j=1; j<=l2; j++){
	DP[i][j] = max(DP[i-1][j], DP[i][j-1], DP[i-1][j-1] + LCS(str1, str2, i-1, j-1));
      }
    }
    //ans[z] = DP[l1][l2];
    std::cout << DP[l1][l2] << std::endl;
  }

  /*for(int z=0; z<q; z++){
    std::cout << ans[z] << std::endl;
    }*/
  return 0;
}

C++: #include <iostream> 
#include <cstring> 
using namespace std;
int c[1001][1001];

int lcs(string x, string y)
{
    int maxl = 0;
    int m = x.length(), n = y.length();
 
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; 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][j-1] + 1; 
            }else
            {
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    return maxl;
}

int main()
{
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1010;
char x[N],y[N];
int c[N][N];
int lcs(char x[],char y[]){

    int lenx = strlen(x+1);
    int leny = strlen(y+1);

    for (int i=0; i<=lenx; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=leny;j++){
        c[0][j] = 0;
        
    }

    for(int i=1;i<lenx;i++){
        for(int j=1;j<leny;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]);
        }
    }
    return c[lenx][leny];
}
int main(){
    int q;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int q;
    cin >> q;
    for(int count = 0; count < q; count++){
        string str_x, str_y;
        cin >> str_x;
        cin >> str_y;
        int length_x, length_y;
        length_x = str_x.size();
        length_y = str_y.size();
        
        vector<vector<int>> common;
        common.resize(length_x+1);
        for(int x = 0; x <= length_x; x++){
            common[x].resize(length_y+1);
        }
        
        for(int x = 0; x <= length_x; x++){
            common[x][0] = 0;
        }
        for(int y = 0; y <= length_y; y++){
            common[0][y] = 0;
        }
        for(int x = 1; x <= length_x; x++){
            for(int y = 1; y <= length_y; y++){
                if(str_x[x] == str_y[y]){
                    common[x][y] = common[x-1][y-1] + 1;
                } else {
                    if(common[x][y-1] > common[x-1][y]){
                        common[x][y] = common[x][y-1];
                    } else {
                        common[x][y] = common[x-1][y];
                    }
                }
            }
        }
        cout << common[length_x][length_y] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
   long L[1010][1010]={{0}}, Z; 
   string X, Y; 
   int q;  
    cin >> q; 
  for(int k=0; k<q; k++){ 
      cin >> X;  
      cin >> Y;
      X = ' ' + X;
      Y = ' ' + Y;
      for(int i=1;i<=X.size();i++) L[i][0]=0;
      for(int j=1;j<=Y.size();j++) L[0][j]=0;
      for(int i=1; i<X.size(); i++){
       for(int j=1; j<Y.size(); j++){
           if(X[i] == Y[j])
                L[i][j]=1+L[i-1][j-1];
           else L[i][j]=max(L[i][j-1], L[i-1][j]); 
          Z=L[i][j];
       } 
     } 
     cout << Z << endl;
  }
   return 0;
}

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

using namespace std;

typedef pair<int,int> pii;

vector<pii> P;

string s,t,rev;

const int MAX_N = 10001;

int dp[MAX_N][MAX_N];

void trace(int i,int j){
	if(dp[i][j] == dp[i-1][j] && dp[i][j] == dp[i][j-1]){
		trace(i-1,j-1);	//??????????§????
	}else if(dp[i][j] == dp[i-1][j]){
		trace(i-1,j);	//???????§????
	}else if(dp[i][j] == dp[i][j-1]){
		trace(i,j-1);	//???????§????
	}else{
		rev += s[i-1];
		if(dp[i-1][j-1] == 0){
			return;
		}
		trace(i-1,j-1);	//??????????§????
	}
}
int main()
{
	string com;
	int n;
	cin >> n;
	for(int l=0;l<n;l++){
	cin >> s;
	cin >> t;
	for(int i=0;i<=s.length();i++){
		dp[i][0] = 0;
	}
	for(int i=0;i<=t.length();i++){
		dp[0][i] = 0;
	}
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			if(s[i] == t[j]){
				dp[i][j] = dp[i-1][j-1]+1;
			}else{
				dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
			}
		}
	}
	printf("%d\n",dp[s.length()][t.length()]);
	}
	/*
	trace(s.length(),t.length());
	for(int i=rev.length();i>0;i--){
		com += rev[i-1];
	}
	cout << com << "\n";	//????????±?????¨???????????????????????????
	*/
}

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

int main(void){
    int L[1010][1010], Z;
    string X, Y;
    int q;
    
    cin >> q;
    for(int k=0; k<q; k++){
        cin >> X;
        cin >> Y;
    for(int i=0; i<X.size(); i++){
        for(int j=0; j<Y.size(); j++){
            L[i][j] = 0;
        }
    }
    
    for(int i=0; i<X.size(); i++){
        for(int j=0; j<Y.size(); j++){
            if(i<=0 || j<=0){
                if(X[i]==Y[j])  L[i][j]=1;
                else            L[i][j]=0;
            }
            else if(X[i] == Y[j])    L[i][j]=1+L[i-1][j-1];
            else L[i][j]=max(L[i][j-1], L[i-1][j]);
            Z=L[i][j];
        }
    }
    
    cout << Z << endl;
    
    }
    return 0;
}