Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	for i:=1; i<lenS+1; i++ {
		for j:=1; j<lenT+1; j++ {
			if S[i-1] == T[j-1] {
				dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	fmt.Println(dp[lenS][lenT])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

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;
}