Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

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

string x;
string y;

int lcs(string x, string y){

  int c[1024][1024] = {{}};

  for(int i = 1;i <= x.size();i++){
    for(int j = 1;j <= y.size();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]);

/*
      for(int k = 1;k <= x.size();k++){
        for(int l = 1;l <= y.size();l++){
          cout << c[i][j] << ' ';
        }
        cout << endl;
      }

      */
    }
  }

  return c[x.size()][y.size()];
}



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

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

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
  int q;
  int ans[100]={};
  cin>>q;
  for(int cn=0;cn<q;cn++){
    string x,y;
    cin>>x>>y;
    for(int i=0;i<x.size();i++){
      for(int j=0;j<y.size();j++){
	if(x[i]==y[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
      }
    }
    ans[cn]=dp[x.size()][y.size()];
    //cout<<dp[x.size()][y.size()]<<endl;
  }
  for(int i=0;i<q;i++)cout<<ans[i]<<endl;
  return 0;
}

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

using namespace std;

class Dataset{
private:
 string X;
 string Y;
public:
 Dataset(){
  string tmp = "";
  cin >> tmp; X = tmp; X = " " + X;
  cin >> tmp; Y = tmp; Y = " " + Y;
 };

 unsigned long getLongestCommonLength(){
  unsigned long Xsize = X.size();
  unsigned long Ysize = Y.size();
 
  vector< vector<unsigned long> > LC(Xsize, vector<unsigned long>(Ysize, 0));

  for(unsigned long X_i = 1; X_i < Xsize; ++X_i){
   for(unsigned long Y_i = 1; Y_i < Ysize; ++Y_i){
    unsigned long tmp = LC[X_i-1][Y_i-1];
    if(X[X_i] == Y[Y_i]) ++tmp;
    if(tmp < LC[X_i-1][Y_i]) tmp = LC[X_i-1][Y_i];
    if(tmp < LC[X_i][Y_i-1]) tmp = LC[X_i][Y_i-1];
    LC[X_i][Y_i] = tmp;
//cout << LC[X_i][Y_i] << " ";
   }
//cout << endl;
  }

  return LC[Xsize-1][Ysize-1];
 };


protected:
};

int main(){
 long datasetNum = 0; cin >> datasetNum;
 for(unsigned long dataset_i = 0; dataset_i < datasetNum; ++dataset_i){
  Dataset data;
  cout << data.getLongestCommonLength() << endl;
 }

 return 0;
};

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

using namespace std;

int main() {
  int T;
  cin >> T;
  for (int t=0; t<T; t++) {
    string word1, word2;
    cin >> word1 >> word2;
    int m = word1.size();
    int n = word2.size();
    int c[m+1][n+1]={};
    int max_len = 0;
    word1 = ' ' + word1;
    word2 = ' ' + word2;

    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (word1[i] == word2[j]) {
          c[i][j] = c[i-1][j-1] + 1;
        }
        else {
          c[i][j] = max(c[i-1][j], c[i][j-1]);
        }
        max_len = max(max_len, c[i][j]);
      }
    }
    cout << max_len << endl;
  }
  return 0;
}

#if 0
???????????????30????????????
?????????0??????????????????????????????????¬?????????????0??§??????????????????????????????1???????§????????????¨??§
????????????????????????????????????????????????????????????
#endif

C++: #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int q;

  	cin >> q;
	for(int i=0;i<q;i++){
		string x, y;
		cin >> x >> y;
        int n, m;
        n = x.size();
        m = y.size();
		int dp[n+1][m+1];
		for(int j=0;j<=n;j++){
          for(int k=0;k<=m;k++){
			dp[j][k] = 0;
			}
		}
		
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(x[j]==y[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][k+1], max(dp[j+1][k], dp[j][k]));
				}
			}
		}
		
		
		
		cout << dp[n][m] <<endl;
  
	}
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    int q;
    cin >> q;
    rep(i,q) {
        string x,y;
        cin >> x >> y;
        int dp[1050][1050] = {};
        rep(i,(int)x.length()) {
            rep(j,(int)y.length()) {
                if(i == 0 || j == 0) {
                    if(x[i] == y[j]) {
                        dp[i][j] = 1;
                    }
                } else 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.length()-1][y.length()-1] << endl;
    }
	return 0;
}