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>
using namespace std;
int main(void){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        string X,Y;
        cin >> X >> Y;
        int L[X.length()+10][Y.length()+10];
        for(int j = 0;j < X.length()+10;j++){
            for(int k = 0;k < X.length()+10;k++){
                L[j][k] = 0;
            }
        }
        for(int j = 1;j<=X.length();j++){
            for(int k = 1;k<=Y.length();k++){
                if(Y[k] == X[j]){
                    L[j][k] = 1+L[j-1][k-1];
                }
                else{
                    L[j][k] = max(L[j-1][k],L[j][k-1]);
                }
            }
        }
        cout << L[X.length()][Y.length()] << endl;
    }
return 0;
}

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

int main(){
  int q, cnt, max=0;
  string str1, str2;
  char ch1, ch2;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> str1 >> str2;
    //cout << "cin >> str1 >> str2" << endl;
    for(int j=0;j<(int)str1.size();j++){
      for(int k=0;k<(int)str2.size();k++){
	//cout << "j = " << j << ", k = " << k << endl;
        cnt = 0;
	int l = 0;
	while(1){
	      //str1[j+l] || str2[k+l] || str1[j+l] == str2[k+l]){
	  ch1 = str1[j+l];
	  //  cout << ch1 << " ";
	  ch2 = str2[k+l];
	  //  cout << ch2 <<endl;
	  if(ch1 == ch2 && ch1 != '\0'){
     	    cnt++;
	    l++;
	    //	    cout << "一致" << endl;
	  }else break;
	}
	if(cnt > max) max = cnt;
      }
    }
    cout << max << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 1000


int lcs(std::string X, std::string Y) {
    int c[MAX+1][MAX+1];
    int maxl = 0;
    int m = X.size();
    int n = Y.size();
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 0;
    }
    X = ' ' + X;
    Y = ' ' + Y;
    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] = std::max(c[i-1][j], c[i][j-1]);
            }
            maxl = std::max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    std::string s1, s2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::cin >> s1 >> s2;
        
        printf("%d\n", lcs(s1, s2));
    }
    
    return 0;
}

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

int get_lcs_length(std::string X, std::string Y) {
    int m = X.length();
    int n = Y.length();
    vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));
    X = " " + X;
    Y = " " + Y;

    int max_length = 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] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            max_length = std::max(max_length, c[i][j]);
        }
    }
    return max_length;
}

int main() {
    int q;
    std::cin >> q;
    for (int i = 0; i < q; i ++) {
        std::string X, Y;
        std::cin >> X;
        std::cin >> Y;
        std::cout << get_lcs_length(X, Y) << std::endl;
    }

}

C++: #include<bits/stdc++.h>

using namespace std;

const int N=1010;

int dp[N][N];

int main()
{
    int n;

    char s1[N],s2[N];

    cin>>n;

    while(n--)
    {
        cin>>(s1+1)>>(s2+1);

        int len1=strlen(s1+1),len2=strlen(s2+1);
        for(int i=1;i<=len1;i++)
        {
            for(int j=1;j<=len2;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]);
                }
            }
        }

        cout<<dp[len1][len2]<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int q;
char X[1000], Y[1000];
int dp[1001][1001];

int main(void) {

    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        scanf("%s %s", X, Y);
        int xlen = strlen(X), ylen = strlen(Y);
        for (int x = 0; x < xlen; ++x) {
            for (int y = 0; y < ylen; ++y) {
                if (X[x] == Y[y]) {
                    dp[x + 1][y + 1] = dp[x][y] + 1;
                }
                else {
                    if (dp[x + 1][y] > dp[x][y + 1]) {
                        dp[x + 1][y + 1] = dp[x + 1][y];
                    }
                    else {
                        dp[x + 1][y + 1] = dp[x][y + 1];
                    }
                }
            }
        }
        printf("%d\n", dp[xlen][ylen]);
        memset(dp, 0, sizeof(int)*1001*1001);
    }

    return 0;
}

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

int solve(string ss,string tt){
  int c[1001][1001];
  int m=ss.size();
  int n=tt.size();
  int k=0;
  ss=' '+ss;
  tt=' '+tt;
  for(int i=0;i<=m;i++)c[0][i]=0;
  for(int i=0;i<=n;i++)c[i][0]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(ss[i]==tt[j]){
        c[i][j]=c[i-1][j-1]+1;
      }
      else{
        c[i][j]=max(c[i][j-1],c[i-1][j]);
      }
      k=max(k,c[i][j]);
    }
  }
  return k;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string ss,tt;
    cin>>n;
    rep(i,n){
      cin>>ss>>tt;
      cout<<solve(ss,tt)<<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 = 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++: /*
 * ALDS1_10_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

//int dp[1001][1001];

int lcm(char* X, char* Y, int nx, int ny) {
int dp[1001][1001];
	dp[1][1] = (X[0] == Y[0]);
	for(int i=1; i<=nx; i++) {
		for(int j=1; j<=ny; j++) {
			dp[i][j] = (X[i-1]==Y[j-1]) + dp[i-1][j-1];
			dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
			dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
		}
	}
	return dp[nx][ny];
}

int main() {
	int q;
	scanf("%d", &q);
	char X[1001];
	char Y[1001];
	while(q--) {
		scanf("%s", X);
		scanf("%s", Y);
		int nx = (int)strlen(X);
		int ny = (int)strlen(Y);
		printf("%d\n", lcm(X, Y, nx, ny));
	}
}