Go: package main

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

const max int = 1000 + 1
var A [][]int

func lcs(x, y string) int {
	x = " " + x
	y = " " + y
	for i:=0;i<len(x); i++ {
		for j:=0;j<len(y); j++ {
			A[i][j] = 0
		}
	}
	for i:=1; i<len(x); i++ {
		for j:=1; j<len(y); j++ {
			if x[i] == y[j] {
				A[i][j] = A[i-1][j-1] + 1
			} else if A[i-1][j] > A[i][j-1] {
				A[i][j] = A[i-1][j]
			} else {
				A[i][j] = A[i][j-1]
			}
		}
	}
	return A[len(x)-1][len(y)-1]
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num 
}

func nextStr(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}


func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	A = make([][]int, max)
	for i := range A {
		A[i] = make([]int, max)
	}
	n := nextInt(scanner)
	for i:=0; i<n; i++ {
		x := nextStr(scanner)
		y := nextStr(scanner)
		fmt.Printf("%d\n", lcs(x, y))
	}
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

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

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

void solve()
{
  string S, T;
  cin >> S >> T;
  int N, M;
  N = S.size(), M = T.size();
  ll dp[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++)
  {
    for (int j = 0; j < M + 1; j++)
    {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      if (S[i] == T[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[N][M] << endl;
}

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

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

int LCS(string p, string q) {
	vector<vector<int>> f(p.size()+1, vector<int>(q.size()+1,0));
	int t;
	for (int i = 1; i <= p.size(); i++) {
		for (int j = 1; j <= q.size(); j++) {
			if (p[i-1] == p[j-1])
				f[i][j] = f[i - 1][j - 1] + 1;
			else if (f[i][j - 1] > f[i - 1][j - 1])
				f[i][j] = f[i][j - 1];
			else
				f[i][j] = f[i - 1][j];
		}
	}
	return f[p.size()][q.size()];
}

int main() {
	int n;
	string p[150];
	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	for (int i = 0; i < n; i++) {
		cout << LCS(p[2*i], p[2 * i + 1])<<endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;

int lcs(int x_begin, int y_begin) {
	int max = 0;
	for (int i = x_begin; X[i] != '\0'; i++) {
		for (int j = y_begin; Y[j] != '\0'; j++) {
			if (X[i] == Y[j]) {
				int v_lcs = lcs(i + 1, j + 1);
				if (v_lcs + 1 > max) {
					max = v_lcs + 1;
				}
			}
		}
	}
	return max;

}

int main() {
	int N;
	cin >> N;
	string stringX, stringY;
	for (int i = 1; i <= N; i++) {
		cin >> stringX >> stringY;
		X = stringX.c_str();
		Y = stringY.c_str();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>

constexpr int MAX = 1000;
char ls[MAX];
char rs[MAX];
int table[MAX + 1][MAX + 1];


void calc_lcs() {
    scanf("%s", ls);
    scanf("%s", rs);
    int l_len = int(std::strlen(ls));
    int r_len = int(std::strlen(rs));
    for (int i = 0; i < l_len; i++) {
        table[i][0] = 0;
    }
    for (int i = 0; i < r_len; i++) {
        table[0][i] = 0;
    }

    for (int l_i = 1; l_i < l_len + 1; l_i++) {
        for (int r_i = 1; r_i < r_len + 1; r_i++) {
            if (ls[l_i - 1] == rs[r_i - 1]) {
                table[l_i][r_i] = table[l_i - 1][r_i - 1] + 1;
            } else {
                table[l_i][r_i] = std::max(table[l_i][r_i - 1], table[l_i - 1][r_i]);
            }
        }
    }
    std::cout << table[l_len][r_len] << std::endl;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        calc_lcs();
    }
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define all(obj) (obj).begin(), (obj).end()
#define fi first
#define sc second
#define pb push_back
#define str to_string
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

ll dp[1010][1010];

ll LCS(string a, string b) {
    int N = a.size();
    int M = b.size();
    memset(dp, 0, sizeof(dp));

    rep(i, 0, N+1) rep(j, 0, M+1) {
        if (i < N) {
            chmax(dp[i+1][j], dp[i][j]);
        }
        if (j < M) {
            chmax(dp[i][j+1], dp[i][j]);
        }
        if (i < N && j < M && a[i] == b[j]) {
            chmax(dp[i+1][j+1], dp[i][j]+1);
        }
    }
    return dp[N][M];
}

int main() {
    int Q;
    string a, b;
    cin >> Q;
    rep(i, 0, Q) {
        cin >> a;
        cin >> b;
        cout << LCS(a, b) << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;

int get_LCS(string x, string y){
  int nx = x.size(), ny = y.size();
  int dp[nx+1][ny+1];
  for(int i=0;i<=ny;i++) dp[0][i] = 0;
  for(int i=0;i<=nx;i++) dp[i][0] = 0;
  for(int i=1;i<=nx;i++){
    for(int j=1;j<=ny;j++){
      if(x[i-1] == y[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }
  }
  /*for(int i=1;i<=nx;i++){
    for(int j=1;j<=ny;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  return dp[nx][ny];
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int q; cin >> q;
  for(int i=0;i<q;i++){
    string x, y; cin >> x >> y;
    cout << get_LCS(x, y) << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

signed main() {
  int n; cin >> n;
  string x,y;
  while(n--){
    cin >> x >> y;
    vector<vector<int> > dp(x.size()+1,vector<int>(y.size()+1));
    for(int i=0;i<x.size();++i){
      for(int j=0;j<y.size();++j){
	if(x[i]==y[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[x.size()][y.size()] << endl;
  }
  
  return 0;
}

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=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;
 
}