Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin >> n;
    rep(i,n){
        string a,b;
        cin >> a >> b;
        int n1 = a.size();
        int n2 = b.size();
        int dp[n1+1][n2+1];
        rep(i,n1+1)rep(j,n2+1)dp[i][j] = 0;
        rep(i,n1)rep(j,n2){
            if(a[i] == b[j]&&dp[i+1][j] == dp[i][j+1]&&dp[i][j] ==dp[i+1][j])dp[i+1][j+1] = dp[i+1][j]+1;
            else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
        cout << dp[n1][n2] << endl;
    }
    return 0;
}

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

int charCode(char charactor) {
	if(charactor>='a' && charactor <= 'z') return (int)(charactor-'a');
	else return (int)(charactor-'A'+26);
}

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

int longestSQ(string& shortword, string& longword) {
	int i,j;
	string tempstr,prestr;
	vector<vector<int> > charMap(52);
	queue<string> targetword;
	map<string,bool> inqueue;
	for(i=0; i<(int)longword.size(); ++i) {
		charMap[charCode(longword[i])].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<bits//stdc++.h>
using namespace std;
int dp[160][1010][1010];


int main(){
    int q;
    cin >> q;
    string a[q],b[q];
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i]; 
    }

    for(int i = 0; i < q; i++){
        for(int j = 0; j < a[i].size(); j++){
            for(int k = 0; k < b[i].size(); k++){
                dp[i][j][k] = 0;
            }
        } 
    }


    int match = 0;
    int value = 0;
    for(int i = 0; i < q; i++){
        for(int j = 1; j < a[i].size() + 1; j++){
            for(int k = 1; k < b[i].size() + 1; k++){
                if(a[i][j - 1] == b[i][k - 1]) match = 1;
                else match = 0;
                value = max({dp[i][j - 1][k - 1] + match, dp[i][j - 1][k], dp[i][j][k - 1]});
                dp[i][j][k] = value;
            }
        } 
    }
    for(int i = 0; i < q; i++){
        cout << dp[i][a[i].size()][b[i].size()] << endl;
    }
    return 0;
}

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

int n, m;
char s[1000], t[1000];
int dp[1001][10001];

int main(void){
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> s;
        cin >> t;
        int sizeofs = strlen(s);
        int sizeoft = strlen(t);
        for(int i=0;i<sizeofs;i++){
            for(int j=0;j<sizeoft;j++){
                if(s[i] == t[j]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }else{
                    dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
                }
                cout << s[3] << endl;
            }
        }
        cout << dp[sizeofs][sizeoft] <<endl;
    }

    return 0;
}

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

#define NMAX 1000
int lcs[NMAX+1][NMAX+1];

int solveLCS(string S1, string S2) {
	int n1 = S1.size(), n2 = S2.size(), vmax = 0;
	
	for (int i = 0; i <= n1; i++) lcs[i][0] = 0;
	for (int i = 0; i <= n2; i++) lcs[0][i] = 0;

	for (int i = 1; i <= n1; i++) {
		for (int j = 1; j <= n2; j++) {
			if (S1[i - 1] == S2[j - 1]) {
				lcs[i][j] = lcs[i - 1][j - 1] + 1;
			}
			else {
				lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
			}
			vmax = max(vmax, lcs[i][j]);
		}
	}
	return vmax;
}

int main() {
	int N; cin >> N;
	string S1, S2;

	for (int i = 0; i < N; i++) {
		cin >> S1 >> S2;
		cout << solveLCS(S1, S2) << endl;
	}
	return 0;
}

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

using namespace std;

string s, t;

int main() {
	int n;
	cin >> n;
	while (n--) {
		//dp[i][j] := s???i??????????????§???t???j??????????????§?????£?????¨??????LCS
		vector<vector<int>> dp(200, vector<int>(200));
		cin >> s >> t;
		dp[0][0] = (s[0] == t[0]);
		for (int i = 1; i < s.size(); i++)dp[i][0] = (bool)(dp[0][0] + (s[i] == t[0]));
		for (int j = 1; j < t.size(); j++)dp[0][j] = (bool)(dp[0][0] + (s[0] == t[j]));
		
		for (int i = 1; i < s.size(); i++) {
			for (int j = 1; j < t.size(); j++) {
				if (s[i] == t[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[s.size() - 1][t.size() - 1] << endl;
	}
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int Q;
    string X, Y;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        cin >> X >> Y;
        int DP[1001][1001];
        memset(DP, 0, sizeof(DP));
        for (int sx = 1; sx <= X.size(); ++sx) {
            for (int sy = 1; sy <= Y.size(); ++sy) {
                DP[sx][sy] = max(DP[sx][sy-1], DP[sx][sy-1]);
                if (X[sx] == Y[sy]) {
                    DP[sx][sy] = max(DP[sx][sy], DP[sx-1][sy-1]+1);
                }
            }
        }
        cout << DP[X.size()][Y.size()] << endl;
    }
    return 0;
}

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

int C[1001][1001];

int lcs(string X,string Y){
  int m=X.length();
  int n=Y.length();
  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.at(i)==Y.at(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;
 }