Go: package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

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


int main() {
	int n, m, q;
	string a, b;//two sequences
	int M[1001][1001] = { { 0 } };//Memory matrix

	cin >> q;
	for (int l = 0; l < q; l++)
	{
		cin >> a >> b;
		n = a.length();
		m = b.length();
		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= m; j++)
			{
				if (a[i] == b[j])
				{
					M[i + 1][j + 1] = M[i][j] + 1;
				}
				else
				{
					M[i + 1][j + 1] = max(M[i][j + 1], M[i + 1][j]);
				}
			}
		}

		cout << M[n][m] << endl;//The time complexity equals to O (n * m)
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

string X, Y;

void solve(int x_size, int y_size)
{
	vector< vector<int> > dp(x_size + 1, vector<int>(y_size + 1));

	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] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}

	cout << dp[X.size()][Y.size()] << endl;
}

int main()
{
	int n;
	cin >> n;
	REP(i, n) {
		cin >> X >> Y;
		solve(X.size(), Y.size());
	}
	return 0;
}

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

int max(int a, int b, int c);

int main(){
    int n;
    std::cin >> n;
    std::string str1;
    std::string str2;
    for(int i=0;i<n;i++){
        std::cin >> str1;
        std::cin >> str2;
        int size1 = str1.size();
        int size2 = str2.size();
        int dp[size1+1][size2+1];
        dp[0][0] = 0;
        for(int j=0;j<=size1;j++){
            dp[j][0] = 0;
        }
        for(int j=0;j<=size2;j++){
            dp[0][j] = 0;
        }

        for(int j=0;j<size1;j++){
            for(int k=0;k<size2;k++){
                if(str1[j]==str2[k]){
                    dp[j+1][k+1] = max(dp[j][k+1],dp[j][k] + 1,dp[j+1][k]);
                }else{
                    dp[j+1][k+1] = max(dp[j][k+1],dp[j][k],dp[j+1][k]);
                }
            }
        }

        std::cout << dp[size1][size2] << std::endl;
    }
    return 0;
}

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

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

int main(){
    //input
    long long q;
    cin >> q;
    long long i,j,k, m, n;
    string S, T;
    const char *s = NULL, *t = NULL;
    for(k = 1; k <= q; k++){
        cin >> S;
        m = S.length();
        s = S.c_str();
        cin >> T;
        n = T.length();
        t = T.c_str();
        long long dp[m+1][n+1];
        for(i = 0; i<= m; i++){
            dp[i][0] = 0;
        }
        for(j = 0; j <= n; j++){
            dp[0][j] = 0;
        }
        for(i = 1; i <= m; i++){
            for(j = 1; j <= n; j++){
                dp[i][j] = max({dp[i-1][j-1] + (s[i-1]==t[j-1]) , dp[i-1][j], dp[i][j-1]});
            }
        }
        cout<< dp[m][n] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int q; cin >> q;
    arr<int> dp(1005, vector<int>(1005, 0));
    string s, t;
    rep(i, q){
        cin >> s >> t;
        int s_l = s.size(), t_l = t.size();
        rep(si, s_l) rep(ti, t_l){
            if(s[si]==t[ti]){
                dp[si+1][ti+1] = max(dp[si][ti]+1, dp[si+1][ti]);
            }else{
                dp[si+1][ti+1] = max(dp[si+1][ti], dp[si][ti+1]);
            }
        }

        pr(dp[s_l][t_l]);
        rep(si, s_l+1) rep(ti, t_l+1) dp[si][ti] = 0;
    }
    return 0;}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[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[m][n];
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		scanf("%s %s", s1, s2);
		printf("%d\n", lcs(s1,s2));
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int q; cin >> q;
  for(int i = 0; i < q; i++){
    string x, y; cin >> x >> y;
    int xn = x.size(), yn = y.size();
    vector<vector<int> > lcs(xn + 1, vector<int>(yn + 1));
    for(int i = 0; i <= xn; i++) lcs[i][0] = 0;
    for(int i = 0; i <= yn; i++) lcs[0][i] = 0;
    for(int j = 1; j <= xn; j++){
      for(int k = 1; k <= yn; k++){
        if(x[j - 1] == y[k - 1]) lcs[j][k] = lcs[j - 1][k - 1] + 1;
        else lcs[j][k] = max(lcs[j - 1][k], lcs[j][k - 1]);
      }
    }
    cout << lcs[xn][yn] << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}

C++: 

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
#define LEN  1001
int Position[LEN][LEN];//每个坐标都是LCS的长度
int includeGetLCS(string first, string second)
{
	int firstlen = first.size();
	int secondlen = second.size();//得到string的长度
	first = " " + first, second = " " + second;//在前面加个空格，以便下面；
	int Position[LEN][LEN];//每个坐标都是LCS的长度
	for (int i = 0; i <= secondlen; i++) Position[0][i]=0;//任意一方没有数据，LCS为0；
	for (int i = 1; i <=firstlen; i++)Position[i][0]=0;
	for (int i = 1; i <= firstlen; i++)
	{
		for (int j = 1; j <= secondlen; j++)
		{
			if (first[i] == second[j])//最后一个相等时候
				Position[i][j] = Position[i - 1][j - 1] + 1;//前面的LCS+1；
			else
			{
				if (Position[i][j - 1] >= Position[i - 1][j])//不相等的时候，比较各自减一的LCS，取最大的那个LCS
					Position[i][j] = Position[i][j - 1];
				else
					Position[i][j] = Position[i - 1][j];
			}
		}

	}
int max=0;
	if (max >= Position[firstlen][secondlen])
		return max;
	else
		return	Position[firstlen][secondlen];
}
int main()
{
	string first, second;
	int number;
	cin >> number;
	for (int i = 0; i < number; i++)
	{
		cin >> first>>second;
		cout << includeGetLCS(first, second)<<endl;
	}
}