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 <string.h>

void CSLength(char *,char *);

int c[1000][1000],a[1000];

int main() {
  int i,j=0,q;
  char s[1000],x[1000],y[1000];

  scanf("%d",&q);

  for(i=0;i<q;i++){

    scanf("%s",s);
    strcpy(&x[1],s);

    scanf("%s",s);
    strcpy(&y[1],s);

    CSLength(x,y);
    a[i]=c[strlen(x)-1][strlen(y)-1];
  }

  for(i=0;i<q;i++){
    printf("%d\n",a[i]);
  }

  return 0;
}

void CSLength(char *x,char *y){
  int m,n,i,j;

  m = strlen(x);
  n = strlen(y);

  for(i=1;i<m;i++) c[i][0] = 0;
  for(j=1;j<n;j++) c[0][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 if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }
      else c[i][j] = c[i][j-1];
    }
  }
}

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();

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (X[i] == Y[j]) 
        if (i == 0 || j == 0) 
          c[i][j] = 1;
        else 
          c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
    }
  }
  return c[m - 1][n - 1];
}

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;
int C[1001][1001];
int lc(string F, string S){
    fill(C[0],C[1000],0);
    int m = F.size(), n = S.size();
    int len=0;
    for(int i=0; i<m; i++){
        for (int j = 0; j < n; ++j) {
            if (F[i] == S[j]) {
                if (i - 1 >= 0 && j - 1 >= 0)
                    C[i][j] = C[i - 1][j - 1] + 1;
                else
                    C[i][j] = 1;
            } else if (i - 1 >= 0 && j - 1 >= 0) {
                C[i][j] = max(C[i][j - 1], C[i][j - 1]);
            }
            len = max(len, C[i][j]);
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ar[n*2];
    for (int i = 0; i < n * 2; ++i) {
        cin >> ar[i];
    }
    for (int j = 0; j < n*2; j+=2) {
        cout << lc(ar[j],ar[j+1]) << endl;
    }
    return 0;
}

C++: // 最長共通部分列 問題
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_LEN 1000
// 無効な値の定義
const int INV = -1;

int longestCommonSubstring(char a[], char b[]);

int main(void)
{

    int q, len;
    char first_str[MAX_LEN], second_str[MAX_LEN];

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> first_str;
        cin >> second_str;

        len = longestCommonSubstring(&first_str[0], &second_str[0]);
        printf("%d\n", len);
    }



    return 0;
}

// 最長共通部分列を算出する関数
int longestCommonSubstring(char a[], char b[])

{
    int dp[MAX_LEN + 1][MAX_LEN + 1];
    int a_len, b_len;

    a_len = strlen(a);
    b_len = strlen(b);

    // 配列の初期化
    for(int i = 0; i < a_len; i++)
    {
        for(int j = 0; j < b_len; j++)
        {
            dp[i][j] = INV;
        }
    }

    for(int i = 0; i < a_len; i++)
    {
        dp[i][0] = 0;
    }

    for(int j = 0; j < b_len; j++)
    {
        dp[0][j] = 0;
    }

    // 最長共通部分列の算出
    for(int i = 1; i <= a_len; i++)
    {
        for(int j = 1; j <= b_len; 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]);
            }
        }
    }

	return dp[a_len][b_len];
}

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

#define STR_MAX 1000

int mat[STR_MAX+1][STR_MAX+1];

int common_subsequence(int len1, int len2, string str1, string str2){
  int i, j;

  for(i=1; i<=len1; i++){
    for(j=1; j<=len2; j++){
      if(str1[i-1] == str2[j-1]) mat[i][j]=mat[i-1][j-1]+1;
      else mat[i][j]=max(mat[i-1][j], mat[i][j-1]);
    }
  }

  return mat[len1][len2];
}

int main(void){
  int i, n;
  string str1, str2;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    cin >> str1 >> str2;

    int len1=str1.size(), len2=str2.size();
    printf("%d\n", common_subsequence(len1, len2, str1, str2));
  }
  
  return 0;
}

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

int main() {
  int q; cin >> q;
  vector<vector<string>> retsu(150, vector<string>(2));
  rep(i, q) {
    cin >> retsu[i][0] >> retsu[i][1];
//    cout << retsu[i][0] << retsu[i][1] << endl;
  }
  
  rep(i, q) {
    string a_1 = retsu[i][0], a_2 = retsu[i][1];
    int b_1 = (int)a_1.size(), b_2 = (int)a_2.size();
//    cout << b_1 << b_2 << endl;
    
    int dp[b_1 + 1][b_2 + 1];
    memset(dp, 0, sizeof(dp));
    rep(j, b_1) {
      rep(k, b_2) {
        if (a_1[j] == a_2[k]) {
          dp[j+1][k+1] = dp[j][k] + 1;
        }
        else {
          dp[j+1][k+1] = max(dp[j+1][k], dp[j][k+1]);
        }
      }
    }
    
    cout << dp[b_1][b_2] << endl;
    
  }

}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>

using namespace std;

void solve(){
	int n, m;
	time_t start, end;

	cin >> n;
	string A;
	/*for (int i = 0; i < n; i++)*/ cin >> A;
	cin >> m;
	string B;
	cin >> B;
	vector<vector<int>> DP(n + 1, vector<int>(m + 1, 0));
	start = clock();
	
	//for (int i = 0; i < n; i++) DP[i][0] = 0;
	//for (int j = 0; j < m; j++) DP[0][j] = 0;

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; 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]);
		}
	}

	end = clock();

	cout << DP[n][m] << endl;

}

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		solve();
	}
}