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(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	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<iostream>
#include<vector>b
using namespace std;
int main()
{
	int kurikaeshi;
	vector<int> answer;
	cin >> kurikaeshi;
	for (int variable = 0;variable < kurikaeshi;++variable) {
		char X[1024], Y[1024];
		int LX = 0, LY = 0;
		vector<vector<int>> L;
		cin >> X >> Y;
		for (int i = 0;X[i] != 0;++i) LX += 1;
		for (int j = 0;Y[j] != 0;++j) LY += 1;
		L.resize(LX+1);
		for (int k = 0;k < LX + 1;++k) L[k].resize(LY+1);
		for (int i = 0;X[i] != 0;++i) {
			for (int j = 0;Y[j] != 0;++j) {
				if (i == 0 || j == 0) {
					L[i][j] = 0;
				}
				else if (X[i] == Y[j]) {
					L[i+1][j+1] = L[i+1][j] + 1;
				}
				else {
					L[i+1][j+1] = L[i][j+1] > L[i+1][j] ? L[i][j+1] : L[i+1][j];
				}
			}
		}
		answer.push_back(L[LX][LY]+1);
	}
	for (int variable = 0;variable < kurikaeshi;++variable) {
		cout << answer[variable] << endl;
	}
}

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

using namespace std;

int results[1001][1001];

int lcs(string x, string y)
{
    // initialize
    for (int i = 0; i < 1001; ++i) {
        for (int j = 0; j < 1001; ++j)
            results[i][j] = 0;
    }

    int maxlcs = 0;
    for (int i = 1; i <= x.length(); ++i) {
        for (int j = 1; j <= y.length(); ++j) {
            if (x[i-1] == y[j-1])
                results[i][j] = results[i-1][j-1] + 1;
            else
                results[i][j] = max(results[i-1][j], results[i][j-1]);

            if (maxlcs < results[i][j])
                maxlcs = results[i][j];
        }
    }
    return maxlcs;
}

int main()
{
    int n;
    cin >> n;

    vector<string> x(n);
    vector<string> y(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; ++i)
        cout << lcs(x[i], y[i]) << '\n';
}

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

int main() {
    int q;
    cin >> q;
    
    rep(i,q) {
        string X,Y;
        cin >> X >> Y;
        int lX=X.size(), lY=Y.size();
        vector<vector<int>> dp(lX+1, vector<int>(lY+1,0));

        rep(i,lX)
            rep(j,lY)
                if(X.at(i) == Y.at(j))
                    dp.at(i+1).at(j+1) = dp.at(i).at(j)+1;
                else
                    dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j), dp.at(i).at(j+1));

        cout << dp.at(lX).at(lY) << endl;
    }
}

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++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  for(i=1;i<=strlen(X);i++){
    for(j=1;j<=strlen(Y);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];
    }
  }

  xlength=strlen(X);
  ylength=strlen(Y);
}
    

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 <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950

void C (string x, string y){
    int p = x.size() ;
    int q = y.size() ;
    vector<vector<int>> dp (p + 1 , vector<int> (q + 1)) ;
    rep(i, p){
        rep(j, q){
            if(x.at(i) == y.at(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[p][q] << endl;
}

int main() {
    int n ; 
    cin >> n ;
    vector<string> s (n) ;
    vector<string> t (n);
    rep(i, n){
        cin >> s[i] ;
        cin >> t[i] ;
    }
    rep(k, n){
        C(s[k], t[k])  ;
    }
}