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 namespace std;

int lcs(const string & a, const string & b)
{
    vector<vector<int> > dp(a.size(), vector<int>(b.size()));

    for (size_t i = 0; i < dp.size(); ++i) {
        for (size_t j = 0; j < dp[0].size(); ++j) {
            if (a.at(i) == b.at(j)) {
                dp[i][j] = ((i == 0 || j == 0) ? 0 : dp[i - 1][j - 1]) + 1;
            } else {
                dp[i][j] = max(i == 0 ? 0 : dp[i - 1][j],
                               j == 0 ? 0 : dp[i][j - 1]);
            }
        }
    }

    return dp[a.length() - 1][b.length() - 1];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string a, b;
        cin >> a >> b;
        cout << lcs(a, b);
    }

    return 0;
}

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

#define MAX_NUM 100
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>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1001][1001];

int solve(string s1,string s2){
	int m=s1.size() ;
	int n=s2.size() ;
	s1=' '+s1;
	s2=' '+s2;
	memset(dp,0,sizeof(dp));
	int maxl=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;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]);
			}
			maxl=max(maxl,dp[i][j]);
		}
	}
	return maxl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
		string s1,s2;
		cin>>s1>>s2;
		cout<<solve(s1,s2)<<endl;
	}
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL+1][MAXL+1];

int lec(string X,string Y)
{
    int XL = X.length();
    int YL = Y.length();
    for(int i=0;i<=XL;i++)
        C[i][0] = 0;
    for(int i=0;i<=YL;i++)
        C[0][i] = 0;
    for(int i=0;i<=XL;i++)
    {
        for(int j=0;j<=YL;j++)
        {
            if(X[i+1]==Y[j+1])
            {
                C[i+1][j+1] = C[i][j]+1;
            }
            else if(C[i][j+1] > C [i+1][j])
            {
                C[i+1][j+1] = C[i][j+1];
            }else{
                C[i+1][j+1] = C[i+1][j];
            }
        }
    }
    return C[XL][YL];
}

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

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

using namespace std;

typedef long long ll;

int lcs(string X, string Y){
  int x = X.size();
  int y = Y.size();

  int d[y+1][x+1];
  memset(d, 0, sizeof(d));

  for(int i = 1; i <= y; i++){
    char a = Y[i];

    for(int j = 1; j <= x; j++){
      char b = X[j];

      if(a == b){
        d[i][j] = max(d[i][j], d[i-1][j-1] + 1);
      }else{
        d[i][j] = max(d[i][j], max(d[i-1][j], d[i][j-1]));
      }
    }
  }

  return d[y][x];
}

int main(){
  int n;
  string x, y;
  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> x;
    cin >> y;

    cout << lcs(x, y) << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

int q;
string strs[310];
int memo[1010][1010];

void initMemo(int l1, int l2) {
    for (int i = 0; i <= l1; i++) {
        memo[0][i] = 0;
    }

    for (int i = 0; i <= l2; i++) {
        memo[i][0] = 0;
    }
}

void store() {
    cin >> q;
    for (int i = 0; i < 2 * q; i++) {
        cin >> strs[i];
    }
}

// Longest Common Subsequence
void LCS(string s1, string s2) {
    int l1 = s1.length();
    int l2 = s2.length();
    initMemo(l1, l2);

    for (int i = 1; i <= l1; i++) {
        for (int j = 1; j <= l2; j++) {
            if (s1[i - 1] == s2[j - 1]) {
                memo[i][j] = memo[i - 1][j - 1] + 1;
            } else {
                memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
            }            
        }
    }

    cout << memo[l1][l2] << endl;
}

void AllLCS() {
    for (int i = 0; i < 2 * q; i += 2) {
        LCS(strs[i], strs[i + 1]);
    }
}


int main() {
    store();
    AllLCS();

    return 0;
}