Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

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

using namespace std;
static const int N = 1000;

int lenCommon(string s1, string s2)
{
	int m = s1.size();
	int n = s2.size();
	int len = max(m, n);
	vector<vector<int> > dp(N+1, vector<int>(N+1, 0));

	//s1 = " " + s1;
	//s2 = " " + s2;

	//for (int i = 0; i <= len; ++i) dp[i][0] = 0;
	//for (int i = 0; i <= len; ++i) dp[0][i] = 0;

	int ret = 0;
	for (int i = 1; i <= m; ++i)
	{
		for (int j = 1; j <= n; ++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]);

			ret = max(ret, dp[i][j]);
		}
	}
	return ret;
}

int main()
{
	string s1, s2;
	int num; cin >> num;
	for (int i = 0; i < num; ++i)
	{
		cin >> s1 >> s2;
 		int res = lenCommon(s1, s2);
		cout << res << endl;
	}
}

C++: #include<stdio.h>
??
int hantei(char x[], char y[]) {
????int xn = 0, yn = 0, flag = 0, i, j, max = 0;
????int c[1001][1001];
??????
????while (flag == 0)
????{
????????if (x[xn] != '\0')
????????{
????????????xn++;
????????}
????????else
????????{
????????????flag = 1;
????????}
????}
??????
????flag = 0;
??????
????while (flag == 0)
????{
????????if (y[yn] != '\0')
????????{
????????????yn++;
????????}
????????else
????????{
????????????flag = 1;
????????}
????}
????for (i = 1; i < xn + 1; i++) c[i][0] = 0;
????for (j = 1; j < yn + 1; j++) c[0][j] = 0;
??????
????for (i = 1; i < xn + 1; i++)
????{
????????for (j = 1; j < yn + 1; j++)
????????{
????????????if (x[i - 1] == y[j - 1])
????????????{
????????????????c[i][j] = c[i - 1][j - 1] + 1;
????????????}
????????????else if (c[i - 1][j] >= c[i][j - 1])
????????????{
????????????????c[i][j] = c[i - 1][j];
????????????}
????????????else
????????????{
????????????????c[i][j] = c[i][j - 1];
????????????}
????????????if (max < c[i][j]) max = c[i][j];
????????}
????}
??????
????return max;
}
??
int main(void) {
????char x[1000], y[1000];
????int q, i;
??????
????scanf("%d", &q);
??????
????for (i = 0; i < q; i++)
????{
????????scanf("%s", x);
????????scanf("%s", y);
????????printf("%d\n", hantei(x, y));
????}
??????
????return 0;
}

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

bool findSubStr(string& shortword, vector<vector<int> >& charMap) {
	int i,j;
	j=0;
	for(i=0; i<(int)shortword.size(); ++i) {
		if(charMap[shortword[i]-'a'].empty()) return false;
		auto itr=charMap[shortword[i]-'a'].begin();
		while(itr!=charMap[shortword[i]-'a'].end()) {
			if(*itr<j) {
				++itr;
			} else {
				break;
			}
		}
		if(itr==charMap[shortword[i]-'a'].end()) return false;
		j=*itr;
	}
	return true;
}

int longestSQ(string& shortword, string& longword) {
	int i,j;
	string tempstr,prestr;
	vector<vector<int> > charMap(26);
	queue<string> targetword;
	map<string,bool> inqueue;
	for(i=0; i<(int)longword.size(); ++i) {
		charMap[longword[i]-'a'].push_back(i);
	}
	targetword.push(shortword);
	while(!targetword.empty()) {
		tempstr=targetword.front();
		if(findSubStr(tempstr,charMap)) return (int)tempstr.size();
		j=(int)tempstr.size();
		for(i=0; i<j; ++i) {
				tempstr=targetword.front();
				if(i==0 || tempstr[i]!=tempstr[i-1]) {
					tempstr.erase(tempstr.begin()+i);
					if(inqueue.find(tempstr)==inqueue.end()) {
						targetword.push(tempstr);
						inqueue[tempstr]=true;
					}
				}
		}
		targetword.pop();
	}
	return 0;
}

int main() {
	int i,q;
	cin >> q;
	string wordA,wordB;
	for(i=0; i<q; ++i) {
		cin >> wordA >> wordB;
		if(wordA.size()<wordB.size()) {
			printf("%d\n",longestSQ(wordA,wordB));
		} else {
			printf("%d\n",longestSQ(wordB,wordA));
		}
	}
	return 0;
}

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

using namespace std;

int lcs(string s1, string s2) {
    s1 = ' ' + s1;
    s2 = ' ' + s2;
    vector<vector<int>> v(s1.length(), vector<int>(s2.length(), 0));

    for (int i = 1; i < s1.length(); ++i) {
        for (int j = 1; j < s2.length(); ++j) {
            if (s1[i] == s2[j])
                v[i][j] = v[i - 1][j - 1] + 1;
            else
                v[i][j] = max(v[i - 1][j], v[i][j - 1]);
        }
    }

    return v[s1.length() - 1][s2.length() - 1];
}

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

    string s1, s2;
    for (int i = 0; i < n; ++i) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << '\n';
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int q;
    int dp[1005][1005];
    dp[0][0]=0;
    cin>>q;
    rep(z,q){
	string a,b;
	cin>>a>>b;
	
	reps(i,a.size()){
	    reps(j,b.size()){
		if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	cout<<dp[a.size()][b.size()]<<'\n';
    }
				  
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  string a,b;
  int x[1001][1001];
  x[0][0]=0;
  for(int i=1;i<=1000;i++){
    x[0][i]=0;
    x[i][0]=0;
  }
  for(int i=0;i<q;i++){
    cin>>a>>b;
    for(int j=1;j<=a.size();j++){
      for(int l=1;l<=b.size();l++){
	if(a[j-1]==b[l-1]){
	  if(x[j-1][l-1]+1>x[j][l-1]){
	    x[j][l]=x[j-1][l-1]+1;
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}else{
	  if(x[j-1][l-1]>x[j][l-1]){
	    x[j][l]=x[j-1][l-1];
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}
      }
    }
    cout<<x[a.size()][b.size()]<<endl;
  }
  return(0);
}