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 <iostream>
#include <string>
#include <algorithm>
using namespace std;
int dp[1002][1002];

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

C++: #include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;
string a[200];
string b[200];
int dp[10000][10000];

int solve(string a, string b){
  int N = a.length();
  int M = b.length();
  int n = max(N, M);
  rep(i, 0, n+1){
    rep(j, 0, n+1){
      dp[i][j] = 0;
    }
  }

  /*
    ...X
    .....X
    dp[i][j] = dp[i-1][j-1] + 1

    ...X
    .....Y
    dp[i][j] = max(dp[i-1][j], dp[i][j-1])
   */
  
  rep(row, 1, N+1){
    rep(col, 1, M+1){
      if(a[row-1] == b[col-1]){
	dp[row][col] = dp[row-1][col-1] + 1;
      }
      else{
	dp[row][col] = max(dp[row-1][col], dp[row][col-1]);
      }
    }
  }
  /*
  rep(row, 0, n+1){
    rep(col, 0, n+1){
      cout << dp[row][col] << " ";
    }
    cout << endl;
    }*/
  return dp[a.length()][b.length()];
}

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

  rep(i, 0, n){
    cin >> a[i];
    cin >> b[i];
  }
  
  rep(i, 0, n){
    cout << solve(a[i], b[i]) << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string.h>
using namespace std;
int LCS(char *x,char *y);
char x[1001], y[1001];
int lcs[1001][1001];
int main()
{
	int q,i,j;

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

int LCS(char *x, char *y)
{
	int i, j;
	int len_x, len_y;
	len_x = strlen(x);
	len_y = strlen(y);
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			lcs[i][j] = '\0';
		}
		//cout << endl;
	}
	i = 0;
	while (x[i] != y[0]) {
		lcs[i][0] = 0;
		i++;
		if (i == len_x) break;

	}
	for (j = i; j < len_x; j++) {
		lcs[j][0] = 1;
	}
	while (y[i] != x[0]) {
		lcs[0][i] = 0;
		i++;
		if (i == len_y) break;
	}
	for (j = i; j < len_y; j++) {
		lcs[0][j] = 1;
	}

	for (i = 1; i <= len_x; i++) {
		for (j = 1; j <= len_y; j++) {
			if (x[i] == y[j]) {
				lcs[i][j] = lcs[i - 1][j - 1] + 1;
				//printf("lcs[%d][%d]=%d\n", i, j, lcs[i - 1][j - 1] + 1);
			}
			if (x[i] != y[j]) {
				lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
				//printf("lcs[%d][%d]=%d\n", i, j, max(lcs[i - 1][j], lcs[i][j - 1]));
			}
		}
	//cout << endl;

	}
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			//printf("%d ", lcs[i][j]);
		}
		//cout << endl;
	}
	//cout << "len_x=" << len_x << endl << "len_y=" << len_y << endl;
			
	return lcs[i-1][j-1];
}

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

string x;
string y;

int lcs(string x, string y){

  int c[1024][1024] = {{}};

  for(int i = 1;i <= x.size();i++){
    for(int j = 1;j <= y.size();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]);

/*
      for(int k = 1;k <= x.size();k++){
        for(int l = 1;l <= y.size();l++){
          cout << c[i][j] << ' ';
        }
        cout << endl;
      }

      */
    }
  }

  return c[x.size()][y.size()];
}



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

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

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
  int q;
  int ans[100]={};
  cin>>q;
  for(int cn=0;cn<q;cn++){
    string x,y;
    cin>>x>>y;
    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]=max(dp[i+1][j+1],dp[i][j]+1);
	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
      }
    }
    ans[cn]=dp[x.size()][y.size()];
    //cout<<dp[x.size()][y.size()]<<endl;
  }
  for(int i=0;i<q;i++)cout<<ans[i]<<endl;
  return 0;
}

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

using namespace std;

class Dataset{
private:
 string X;
 string Y;
public:
 Dataset(){
  string tmp = "";
  cin >> tmp; X = tmp; X = " " + X;
  cin >> tmp; Y = tmp; Y = " " + Y;
 };

 unsigned long getLongestCommonLength(){
  unsigned long Xsize = X.size();
  unsigned long Ysize = Y.size();
 
  vector< vector<unsigned long> > LC(Xsize, vector<unsigned long>(Ysize, 0));

  for(unsigned long X_i = 1; X_i < Xsize; ++X_i){
   for(unsigned long Y_i = 1; Y_i < Ysize; ++Y_i){
    unsigned long tmp = LC[X_i-1][Y_i-1];
    if(X[X_i] == Y[Y_i]) ++tmp;
    if(tmp < LC[X_i-1][Y_i]) tmp = LC[X_i-1][Y_i];
    if(tmp < LC[X_i][Y_i-1]) tmp = LC[X_i][Y_i-1];
    LC[X_i][Y_i] = tmp;
//cout << LC[X_i][Y_i] << " ";
   }
//cout << endl;
  }

  return LC[Xsize-1][Ysize-1];
 };


protected:
};

int main(){
 long datasetNum = 0; cin >> datasetNum;
 for(unsigned long dataset_i = 0; dataset_i < datasetNum; ++dataset_i){
  Dataset data;
  cout << data.getLongestCommonLength() << 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;
}

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

using namespace std;

int main() {
  int T;
  cin >> T;
  for (int t=0; t<T; t++) {
    string word1, word2;
    cin >> word1 >> word2;
    int m = word1.size();
    int n = word2.size();
    int c[m+1][n+1]={};
    int max_len = 0;
    word1 = ' ' + word1;
    word2 = ' ' + word2;

    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (word1[i] == word2[j]) {
          c[i][j] = c[i-1][j-1] + 1;
        }
        else {
          c[i][j] = max(c[i-1][j], c[i][j-1]);
        }
        max_len = max(max_len, c[i][j]);
      }
    }
    cout << max_len << endl;
  }
  return 0;
}

#if 0
???????????????30????????????
?????????0??????????????????????????????????¬?????????????0??§??????????????????????????????1???????§????????????¨??§
????????????????????????????????????????????????????????????
#endif