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 <vector>
#include <algorithm>
using std::vector;

int get_lcs_length(std::string X, std::string Y) {
    int m = X.length();
    int n = Y.length();
    vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));
    X = " " + X;
    Y = " " + Y;

    int max_length = 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] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            max_length = std::max(max_length, c[i][j]);
        }
    }
    return max_length;
}

int main() {
    int q;
    std::cin >> q;
    for (int i = 0; i < q; i ++) {
        std::string X, Y;
        std::cin >> X;
        std::cin >> Y;
        std::cout << get_lcs_length(X, Y) << std::endl;
    }

}

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

using namespace std;

const int N=1010;

int dp[N][N];

int main()
{
    int n;

    char s1[N],s2[N];

    cin>>n;

    while(n--)
    {
        cin>>(s1+1)>>(s2+1);

        int len1=strlen(s1+1),len2=strlen(s2+1);
        for(int i=1;i<=len1;i++)
        {
            for(int j=1;j<=len2;j++)
            {
                if(s1[i]==s2[j])
                {
                    dp[i][j]=dp[i-1][j-1]+1;
                }else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }

        cout<<dp[len1][len2]<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int q;
char X[1000], Y[1000];
int dp[1001][1001];

int main(void) {

    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        scanf("%s %s", X, Y);
        int xlen = strlen(X), ylen = strlen(Y);
        for (int x = 0; x < xlen; ++x) {
            for (int y = 0; y < ylen; ++y) {
                if (X[x] == Y[y]) {
                    dp[x + 1][y + 1] = dp[x][y] + 1;
                }
                else {
                    if (dp[x + 1][y] > dp[x][y + 1]) {
                        dp[x + 1][y + 1] = dp[x + 1][y];
                    }
                    else {
                        dp[x + 1][y + 1] = dp[x][y + 1];
                    }
                }
            }
        }
        printf("%d\n", dp[xlen][ylen]);
        memset(dp, 0, sizeof(int)*1001*1001);
    }

    return 0;
}

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

int solve(string ss,string tt){
  int c[1001][1001];
  int m=ss.size();
  int n=tt.size();
  int k=0;
  ss=' '+ss;
  tt=' '+tt;
  for(int i=0;i<=m;i++)c[0][i]=0;
  for(int i=0;i<=n;i++)c[i][0]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(ss[i]==tt[j]){
        c[i][j]=c[i-1][j-1]+1;
      }
      else{
        c[i][j]=max(c[i][j-1],c[i-1][j]);
      }
      k=max(k,c[i][j]);
    }
  }
  return k;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string ss,tt;
    cin>>n;
    rep(i,n){
      cin>>ss>>tt;
      cout<<solve(ss,tt)<<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 = 0; 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;
	
}

C++: /*
 * ALDS1_10_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

//int dp[1001][1001];

int lcm(char* X, char* Y, int nx, int ny) {
int dp[1001][1001];
	dp[1][1] = (X[0] == Y[0]);
	for(int i=1; i<=nx; i++) {
		for(int j=1; j<=ny; j++) {
			dp[i][j] = (X[i-1]==Y[j-1]) + dp[i-1][j-1];
			dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
			dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
		}
	}
	return dp[nx][ny];
}

int main() {
	int q;
	scanf("%d", &q);
	char X[1001];
	char Y[1001];
	while(q--) {
		scanf("%s", X);
		scanf("%s", Y);
		int nx = (int)strlen(X);
		int ny = (int)strlen(Y);
		printf("%d\n", lcm(X, Y, nx, ny));
	}
}

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], maxl = 0, i, j;
  int m = x.size();
  int n = y.size();

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

int main(){
  string x, y;
  int q, i;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

string s1, s2;

int lcs() {
  int i, j, flag = 0;
  int dp[s1.length()+1][s2.length()+1] = {};
  
  for(i = 1; i <= s1.length(); i++) {
    for(j = 1; j <= s2.length(); j++) {
      dp[i][j] = max(max(dp[i-1][j-1], dp[i-1][j]), dp[i][j-1]);
      if(s1[i-1] == s2[j-1] && flag == 0) { 
	dp[i][j]++;
	flag++;
      }
      //      cout << dp[i][j] << ' ';
    }
    //    cout << endl;
    flag = 0;
  }
  return dp[s1.length()][s2.length()];
}

int main(){
  int n;
  cin >> n;
  while(n--) {
    cin >> s1 >> s2;
    cout << lcs() << endl;
  }
  
  return 0;
}

C++: #include<cstdio>
#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, n, i, j;

	m = x.size();
	n = y.size();

	int maxl = 0;
	x = ' ' + x;
	y = ' ' + y;

	for (i = 0; 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]);
		}
	}

	return c[m][n];
}

int main() {
	string s1, s2;
	int n, i;
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}