Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    {
        string t;
        getline(cin, t);
    }
    for(int i=0;i<n;i++) {
        string s1, s2;
        getline(cin, s1);
        getline(cin, s2);
        vector<int> v1(s2.size()+1, 0);
        vector<int> v2(s2.size()+1, 0);
        for(auto c1=s1.cbegin(); c1!=s1.cend(); ++c1) {
            int i = 1;
            for(auto c2=s2.cbegin(); c2!=s2.cend(); ++c2,i++) {
                auto m = max(v1[i], v2[i-1]);
                m = max(m, v1[i-1] + (*c1 == *c2 ? 1 : 0));
                v2[i] = m;
            }
            /*
            for(auto t=v1.begin();t!=v1.end();++t) {
                cout << *t << " ";
            }
            cout << endl;
            */
            swap(v1, v2);
        }
        cout << v1[s2.size()] << endl;
    }
}

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

#define MAX_NUM 1001
int fLength;
int sLength;

int memo[MAX_NUM][MAX_NUM];
string f, s;

/*******************
  Longest Common Subsequence
  ??¨??????????????§??????????????????(??¨??????????????§?????????)
 *********************/

void solve() {
  for(int i = 0; i < fLength; i++) {
    for(int j = 0; j < sLength; j++) {
      if(f[i] == s[j]) {
        memo[i + 1][j + 1] = memo[i][j] + 1;
      }
      else {
        memo[i + 1][j + 1] = max(memo[i + 1][j], memo[i][j + 1]);
      }
    }  
  }
}


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


  //?????????
  memset(memo, 0, sizeof(memo));
  for(int i = 0; i < n; i++) {
    cin >> f >> s;
    fLength = f.size();
    sLength = s.size();
    solve();
    cout << memo[fLength][sLength] << endl;
  }
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int q; cin >> q;
    VS X(q), Y(q); REP(i,q) cin >> X[i] >> Y[i];

    REP(k,q){
        int dp[X[k].size()+1][Y[k].size()+1]; REP(i,X[k].size()+1)REP(j,Y[k].size()+1) dp[i][j] = 0;
        REP(i,X[k].size())REP(j,Y[k].size()){
            if(X[k][i] == Y[k][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[X[k].size()][Y[k].size()] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX_SEQ 1000

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

  for(int i=0;i<n;i++) {
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;
    int seq1_len = 0;
    int seq2_len = 0;
    while(seq1[seq1_len] != '\0')
      seq1_len++;
    while(seq2[seq2_len] != '\0')
      seq2_len++;

    /*
    cout << "length" << endl;
    cout << seq1_len << endl;
    cout << seq2_len << endl;
    */

    int lcs[seq1_len+1][seq2_len+1];
    for(int i=0;i<=seq1_len;i++)
      lcs[i][0] = 0;
    for(int i=0;i<=seq2_len;i++)
      lcs[0][i] = 0;

    for(int i=1;i<=seq1_len;i++) {
      for(int j=1;j<=seq2_len;j++) {
        int s1_it = i-1;
        int s2_it = j-1;
        if(seq1[s1_it] == seq2[s2_it]) {
          lcs[i][j] = lcs[i-1][j-1] + 1;
        }
        else {
          lcs[i][j] = max(lcs[i][j-1],lcs[i-1][j]);
        }
      }
    }
    /*
    cout << "lcs[i][j]" << endl;
    for(int i=0;i<=seq1_len;i++) {
      for(int j=0;j<=seq2_len;j++) {
        cout << lcs[i][j] << " ";
      }
      cout << endl;
    }
    */

    cout << lcs[seq1_len][seq2_len] << endl;
  }
}

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

#define MAX_Q 150
#define MAX_LEN 1000
string s, t;
int dp[MAX_LEN+1][MAX_LEN+1];

int align_dp() {
    fill((int*)dp, (int*)(dp+MAX_LEN+1), 0);
    // dp[i][j] := i-1番目、j-1番目までの文字で最長
    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] = max(dp[i][j] + 1, max(dp[i+1][j], dp[i][j+1]));
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    return dp[s.size()][t.size()];
}

int main() {
    int q;
    cin >> q;
    int res[MAX_Q+1];
    for (int i = 0; i < q; i++) {
        cin >> s;
        cin >> t;
        res[i] = align_dp();
    }
    for (int i = 0; i < q; i++)
        cout << res[i] << endl;
    return 0;
}