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++: #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();
    }
    int Answer()const
    {
        return FTable[FArray1.size()][FArray2.size()];
    }
};

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

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

#if 0
所用時間:0.5h

感想:

#endif

int solve(string X, string Y){
  int rows = Y.size();
  int cols = X.size();
  int L[1001][1001] = {}; //L[y][x]の初期化

  //テーブルLの更新
  for(int r = 1; r <= rows; ++r){
    for(int c = 1; c <= cols; ++c){
      if(X[c-1] == Y[r-1]) L[r][c] = 1 + L[r-1][c-1];
      else L[r][c] = max(L[r][c-1], L[r-1][c]);
    }
  }

  // //テーブルの表示
  // cout << "Ltable:" << endl;
  // for(int row=0; row <= rows; ++row){
  //   for(int col = 0; col <= cols; ++col){
  //     cout << L[row][col];
  //   }
  //   cout << endl;
  // }

  return L[rows][cols];
}

int main(){
  int q;
  string X, Y;
  cin >> q;

  for(int i = 0; i < q; ++i){
    cin >> X >> Y;

    int ans = solve(X, Y);

    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int lcs(string x, string y)
{
	int dp[1100][1100];
	memset(dp, 0, sizeof(dp));

	x = " " + x;
	y = " " + y;
	int n = x.size();
	int m = y.size();


	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			if (x[i] == y[j]){
				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 q;
	string s1, s2;
	cin >> q;
	for (int i = 0; i < q; i++) {		
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}

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

const int MAX_LEN = 1000;

int lcs(string x, string y) {
  int a[MAX_LEN + 1][MAX_LEN + 1];
  for (int i = 0; i <= MAX_LEN; i++)
    a[i][0] = a[0][i] = 0;

  for (int i = 1; i <= x.size(); i++) {
    for (int j = 1; j <= y.size(); j++) {
      if (x[i-1] == y[j-1]) {
        a[i][j] = a[i-1][j-1] + 1;
      } else if (a[i][j-1] > a[i-1][j]) {
        a[i][j] = a[i][j-1];
      } else {
        a[i][j] = a[i-1][j];
      }
    }
  }
  return a[x.size()][y.size()];
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;



int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s,t;
        cin >> s >> t;
        int dp[1010][1010];
        for(int i = 0; i < 1010; i++){
            for(int j = 0; j < 1010; j++){
                dp[i][j] = 0;
            }
        }

        for(int i = 0; i < s.size(); i++){
            for(int j = 0; j < t.size(); j++){
                if(s[i] == t[j]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }else{
                    dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
                }
            }
        }
        cout << dp[s.size()][t.size()] << endl;

    }
}