Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1001
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];
 
void solve(void){
  int i,j;
 
  xlength=strlen(X);
  ylength=strlen(Y);
   
  for(i=1;i<=xlength;i++){
    for(j=1;j<=ylength;j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }
}
     
int main()
{
  int i;
   
  scanf("%d",&q);
 
  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }
 
  /*for(i=0;i<q;i++){
    printf("%d\n",count[][]);
    }*/
 
  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 i,j;
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
 
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0]c[j]=0;

  for(i=1;i<=m;i++){
    for(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(i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<enl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#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++)
      {
        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 <bits/stdc++.h>

using namespace std;
#define MAX 1000

int lcs(string X, string Y) {
  int c[MAX+1][MAX+1];
  int m, n;
  m = X.size();
  n = Y.size();
  int maxlen = 0;
  X = ' ' + X;
  Y = ' ' + Y;

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


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

C++: #include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int map[2000][2000];

int main(void) {
    int q;
    scanf("%d",&q);
    for(int i=0; i<q; i++) {
        memset(map, 0, sizeof(map));
        char x[2000], y[2000];
        scanf("%s%s",x,y);
        int xl=strlen(x),yl=strlen(y);

        for(int m=0; m<xl; m++)
            map[m][0] = 0;
        for(int n=0; n<yl; n++)
            map[0][n] = 0;
        for(int m=1; m<=xl; m++)
            for(int n=1; n<=yl; n++) {
                if(x[m-1] == y[n-1])
                    map[m][n] = max(max(map[m-1][n-1]+1, map[m-1][n]), map[m][n-1]);
                else
                    map[m][n] = max(max(map[m-1][n-1]+0, map[m-1][n]), map[m][n-1]);
            }
        printf("%d\n", map[xl][yl]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    int dp[1001][1001];
    cin>>n;
    int i, j, k;
    int ans = 0;
    for(i=0; i<n; i++){
        string s, v;
        cin>>s>>v;
        int l = s.length();
        int m = v.length();
        for(j=0; j<1001; j++){
            for(k=0; k<1001; k++){
                dp[j][k] = 0;
            }
        }
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
                if(s[j] == v[k]){
                    dp[j+1][k+1] = dp[j][k]+1;
                }
                else{
                    dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
                }
            }
        }
        cout<<dp[l][m]<<endl;

    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int lcs[1001][1001];
/*int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};*/
int main()
{
    int num;
    cin>>num;
    for(int l=0;l<num;l++)
    {

        for(int i=0;i<1001;i++)
            for(int j=0;j<1001;j++)
                lcs[i][j]=0;
        string a,b;
        cin>>a>>b;
        //cout<<lcs(a,b)<<endl;
        for(int i=0;i<a.length()+1;i++)
        {
            for(int j=0;j<b.length()+1;j++)
            {
                if(i==0||j==0)
                {
                    lcs[i][j]=0;
                }
                else if(a[i-1]==b[j-1])
                {
                    lcs[i][j]=lcs[i-1][j-1]+1;
                }
                else
                {
					if(lcs[i][j-1]>lcs[i-1][j])
						lcs[i][j]=lcs[i][j-1];
					else
						lcs[i][j]=lcs[i-1][j];
                }
            }
        }
        cout<<lcs[a.length()][b.length()]<<endl;
    }
}

}