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<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; // X[0] に空白を挿入
    Y = ' ' + Y; // Y[0] に空白を挿入
     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 lcs(string str1, string str2) {
	int n1 = str1.size();
	int n2 = str2.size();
	int A[n1 + 1][n2 + 1];
	for (int i = 0; i <= n1; i++) A[i][0] = 0;
	for (int j = 1; j <= n1; j++) A[0][j] = 0;

	for (int i = 1; i <= n1; i++) {
		for (int j = 1; j <= n2; j++) { 
			if (str1[i - 1] == str2[j - 1]) {
				A[i][j] = A[i - 1][j - 1] + 1; 
			} else {
				A[i][j] = max(A[i - 1][j], A[i][j - 1]);
			}
		}
	}
	return A[n1][n2];
}

int main() {
	int n;
	string str1, str2;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
  
static const int N = 1000;
  
int las(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 "stdafx.h"
#include<iostream>
#include<algorithm>
#include<string>
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++) {
			cout << c[i][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() {
	int n;
	string x, y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;

		cout << lcs(x, y) << endl;
	}

	
}

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-1] == y[j-1])
            { 
                // if(i==0 || j==0) c[i][j] = 1;
                c[i][j] = c[i-1][j-1] + 1; 
            }else
            {
                // if(i==0 || j==0) c[i][j] = 0;
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    // printf("%d\n", c[m][n]);
    return c[m][n];
}

int main()
{
    
 //   freopen("n4.txt","r",stdin);
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll q;
    cin>>q;
    rep(i,q){
        string a,b;
        cin>>a>>b;
        VV dp(a.size()+1,V(b.size()+1,0));
        rep(j,a.size()){
            rep(k,b.size()){
                if(a[j]==b[k]){
                    dp[j+1][k+1]=dp[j][k]+1;
                }else{
                    dp[j+1][k+1]=max(dp[j+1][k],max(dp[j][k+1],dp[j][k]));
                }
            }
        }
        cout<<dp[a.size()][b.size()]<<endl;
    }
}

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

int dp[1005][1005];

int lcs(string x, string y){
    for (int i = 1; i <= x.size(); i++){
        for (int j = 1; j <= y.size(); j++)
        {
            if(x[i-1] != y[j-1])
                dp[i][j] = dp[i-1][j] > dp[i][j-1] ? dp[i-1][j] : dp[i][j-1];
            else
                dp[i][j] = dp[i-1][j-1] + 1;
        }
    }
    return dp[x.size()][y.size()];
}

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

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int MAX=1001;
int lcs(string X,string Y) 
{
	int i=0,j=0,c[MAX][MAX],x=X.length(),y=Y.length();
	for(i=0;i<=x;i++)c[i][0]=0;
	for(i=0;i<=y;i++)c[0][i]=0;
	for(i=1;i<=x;i++) 
	for(j=1;j<=y;j++) 
	if(X[i-1]==Y[j-1])c[i][j]=c[i-1][j-1]+1; 
	else c[i][j]=max(c[i][j-1],c[i-1][j]);
	return c[x][y];
}
int main()
{
	int n;cin>>n;
	string X,Y;
	while(n--)
	{
		cin>>X>>Y;
		cout<<lcs(X,Y)<<endl;
	}
}

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

using namespace std;

int solve(string x, string y) {
    int n = x.length();
    int m = y.length();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (x[i - 1] == y[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
           else {
               dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[n][m];
}

int main() {
    int n;
    cin >> n;
    string x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        cout << solve(x, y) << endl;
    }
    return 0;
}