Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

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

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dp[1001][1001];

int main() {
    int q;
    cin >> q;
    REP(i, q) {
        string s, t;
        cin >> s >> t;
        REP(i, s.size() + 1) REP(j, t.size() + 1) dp[i][j] = 0;
        REP(i, s.size()) {
            REP(j, t.size()) {
                if (s[i] == t[j])
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            }
        }
        cout << dp[s.size()][t.size()] << endl;
    }
    return 0;
}

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

#define MAX_N 1000
#define MAX_M 1000

void solve();

string s, t;
int dp[MAX_N + 1][MAX_M + 1];

void solve(){
	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 + 1][j + 1] = dp[i][j] + 1;
				} else {
					dp[i + 1][j + 1] = max(dp[i][j], dp[i + 1][j]);
				}
			}
		}
		cout << dp[s.size()][t.size()] << endl;
}

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

C++: q = int(input())
for i in range(q):
    x = input().rstrip()
    y = input().rstrip()
    n = len(x)
    m = len(y)
    d = [[0 for _ in range(m+1)] for _ in range(n+1)]
    for i in range(n):
        for j in range(m):
            if x[i] == y[j]:
                d[i+1][j+1] = d[i][j]+1
            else:
                d[i+1][j+1] = max(d[i+1][j],d[i][j+1])
    print(d[n][m])

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

int N;
int solve(string s1, string s2){
    vector<vector<int> > dp(s1.size() + 1, vector<int>(s2.size() + 1, 0)); 
    for (int i = 1; i <= s1.size(); ++i){
        for (int j = 1; j <= s2.size(); ++j){
            if (s1[i - 1] == s2[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[s1.size()][s2.size()];
}
int main(){
    cin >> N;
    string temp1, temp2;
    for (int i = 0; i < N; ++i){
        cin >> temp1 >> temp2;
        cout << solve(temp1, temp2) << endl;
    }
}

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

int lcs(string X, string Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j])
	dp[i][j] = dp[i-1][j - 1] + 1;
      else if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

  string X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> Y;

    cout << lcs(X, Y) << 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 i,j;
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
 
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0]c[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{
        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(i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<enl;
  }
  return0;
}

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>
#include<vector>
#include<algorithm>
#include<cmath>

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

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

using namespace std;

int lis(string x, string y){
 vector<vector<int>> v(x.size()+1, vector<int>(y.size()+1));
  REP(i,(int)x.size()+1){
    REP(j,(int)y.size()+1){
      if(i==0 or j==0) v[i][j]=0;
      else if(x[i-1]==y[j-1]){ 
        v[i][j] = v[i-1][j-1]+1;
      }
      else{
        v[i][j]=max(v[i][j-1],v[i-1][j]);
      }
    }
  }
  return v[x.size()][y.size()];
}

int main(void){
  int i,j,q;
  cin >>q;
  string x;
  string y;
  REP(i,q) {
    cin >> x>> y;
    cout << lis(x,y)<< endl;

  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

#define N 1000

int lcs(string X, string Y){
	int i,j,c[N+1][N+1],n,m;
	int maxl = 0;
	m = X.size();
	n = Y.size();

	X = ' ' + X;
	Y = ' ' + Y;

	for(i=1;i<=m;i++) c[i][0] = 0;
	for(j=0;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{
				c[i][j] = max(c[i-1][j],c[i][j-1]);
			}
			maxl = max(maxl,c[i][j]);
		}
	}
	return maxl;
}

int main(void){

	string s1,s2;
	int i,n;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		cin >> s1 >> s2;
		cout << lcs(s1,s2) << endl;
		//printf("%d\n",lcs(s1,s2));
	}
	return 0;
}