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 f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	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])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

C++: 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char len1[1001], len2[1001];
 
LCS(int x, int y){
  int i,j,c[1001][1001];
 
   for(i=0;i<=x;i++){
      c[i][0]=0;
  }
 
  for(j=0;j<=y;j++){
    c[0][j]=0;
  }
 
  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(len1[i-1]==len2[j-1]){
    c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j-1]>=c[i][j-1]){
    c[i][j] = c[i-1][j];
      }else{
    c[i][j] = c[i][j-1];
      }
    }
  }
 
  if(i==0 || j==0){
    return 0;
  }else if(i>0 && j>0 && x == y){
    return c[i-1][j-1];
  }else if(i>0 && j>0 && x!=y){
    return c[x][y];
  }
}
 
main(){
  int n,i,l1,l2,result;
 
  scanf("%d", &n);
   
  for(i=0;i<n;i++){
    scanf("%s",len1);
    scanf("%s",len2);
    l1=strlen(len1);
    l2=strlen(len2);
    
    result=LCS(l1,l2);
    printf("%d\n",result);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
static const int N = 1000;

int lcs(string x, string y);

int main() {
    int n;
    cin >> n;
    string x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    return 0;
}
int lcs(string x, string y) {
    int c[N + 1][N + 1];
    int m = (int)x.size(), n = (int)y.size();
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 1; j <= n; j++) c[0][j] = 0; //c[0][0] is prepared above
    int maxl = 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] = max(c[i-1][j], c[i][j-1]);
            maxl = max(maxl, c[i][j]);
        }
    }
    /*for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }*/
    return maxl;
}

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

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;

int dp[1010][1010];
int main(){
	ios::sync_with_stdio(false);
	int t;
	string a,b;
	cin>>t;
	while(t--){
		memset(dp,0,sizeof(dp));
		cin>>a>>b;
		int lena=a.length();
		int lenb=b.length();
		for(int i=1;i<=lena;i++){
			for(int j=1;j<=lenb;j++){
				if(a[i-1]==b[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else{
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		cout<<dp[lena][lenb]<<endl;
	}


	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

class TLcsSolver
{
    typedef std::vector<std::vector<int> > TTable;
    TTable FTable;
    std::string FArray1;
    std::string FArray2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < FTable.size(); ++i){
            for(std::size_t j = 1; j < FTable[i].size(); ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
public:
    TLcsSolver(const std::string& a, const std::string& b)
     : FArray1(a), FArray2(b)
     , FTable(a.size()+1, std::vector<int>(b.size()+1, 0))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[FArray1.size()][FArray2.size()];
    }
    void Print()const
    {
        for(std::size_t i = 0; i < FTable.size(); ++i){
            for(std::size_t j = 0; j < FTable[i].size(); ++j){
                std::cout << FTable[i][j] << '\t';
            }
            std::cout << '\n';
        }
    } 
};

int main()
{
    int n;
    std::cin >> n;
    char a[1000];
    char b[1000];
    for(int i = 0; i < n; ++i){
        std::gets(a);
        std::gets(b);
        std::printf("%d", TLcsSolver(a, b).Answer());
    }
    return 0;
}