Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	for i := 0; i < num; i++ {
		sc.Scan()
		in1 := sc.Text()
		sc.Scan()
		in2 := sc.Text()
		countMax(in1, in2)
	}
}

func countMax(in1 string, in2 string) {
	counta := make([][]int, len(in2)+1)
	for i := 0; i < len(in2)+1; i++ {
		for j := 0; j < len(in1)+1; j++ {
			counta[i] = append(counta[i], 0)
		}
	}

	// fmt.Println(counta)
	for a1, v1 := range in1 {
		i1 := a1 + 1
		for a2, v2 := range in2 {
			i2 := a2 + 1
			// fmt.Printf("1:%v 2:%v\n", i1, i2)
			if v1 == v2 {
				counta[i2][i1] = counta[i2-1][i1-1] + 1
				continue
			}
			val := counta[i2-1][i1]
			if val < counta[i2][i1-1] {
				val = counta[i2][i1-1]
			}

			counta[i2][i1] = val
		}
	}
	fmt.Println(counta[len(in2)][len(in1)])
}

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