Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

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

C++: // input: alds1_10_c.in
#include<iostream>
using namespace std;

bool x[26], y[26];

int lcs(string& a, string& b) {
  for(int i=0; i<26; i++) {
    x[i] = 0;
    y[i] = 0;
  }

  for(int i=0; i<a.size(); i++) {
    x[a.c_str()[i] - 97] = true;
  }

  for(int i=0; i<b.size(); i++) {
    y[b.c_str()[i] - 97] = true;
  }

  int n = 0;
  for(int i=0; i<26; i++) {
    if(x[i] && y[i])
      n++;
  }

  return n;
}

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

    cout << lcs(a, b) << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


// 最長共通部分列

// dp[決めた桁数][未満フラグ][1を含んでいたか否かフラグ]
#define MAX_LENGTH_S1 (1000)
#define MAX_LENGTH_S2 (1000)
// dp[i][j]:S1[i]までとS2[j]までの最長共通部分列
long long dp[MAX_LENGTH_S1 + 1][MAX_LENGTH_S2 + 1];

int main() {

	int set_num;
	cin >> set_num;
	for (int num = 0; num < set_num; num++) {

		string S1, S2;
		cin >> S1 >> S2;
		int len1 = S1.size();
		int len2 = S2.size();

		dp[0][0] = 0;
		for (int i = 0; i < len1; i++) {
			for (int j = 0; j < len2; j++) {
				if (S1[i] == S2[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, max(dp[i + 1][j], dp[i][j + 1]));
				else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
		int LCS_length = dp[len1][len2];
		cout << LCS_length << 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;
int INF = 1000000009;
int lcs(string s,string t){
    int l = s.size(),r = t.size();
    s += '#';
    t += '=';
    vector<vector<int>> dp(l+2,vector<int>(r+2,-(l+r)));
    dp[0][0] = 0;
    rep(i, l+1)
    {
        rep(j, r+1)
        {
            if(dp[i+1][j]<dp[i][j])dp[i+1][j]=dp[i][j];
            if(dp[i][j+1]<dp[i][j])dp[i][j+1]=dp[i][j];
            if(dp[i+1][j+1]<(dp[i][j]+(s[i]==t[j])))dp[i+1][j+1]=dp[i][j]+(s[i]==t[j]);
        }
    }
    return dp[l][r];
}
int main()
{
    int n;
    string s, t;
    cin >> n;
    vector<int> ans;
    rep(i, n)
    {
        cin >> s >> t;
        ans.push_back(lcs(s, t));
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

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

static const int N = 1000;

int lcs(string X, string Y) {
  int c[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(int i=1; 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[i] == Y[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(void) {
  string s1, s2;
  int n; cin >> n;
  for(int i=0; i<n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    for (int k = 0; k < n; k++)
    {
        string A, B;
        cin >> A >> B;
        int a = A.size();
        int b = B.size();
        vector<vector<int>> dp(b + 1, vector<int>(a + 1, 0));
        for (int i = 0; i < b; i++)
        {
            for (int j = 0; j < a; j++)
            {
                if (B[i] == A[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 << dp[b][a] << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;
 
int lcs(string X,string Y){
  int c[N + 1][N + 1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X= ' ' + X;
  Y= ' ' + Y;
  
  for(int i=1;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[i]==Y[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;
}

C++: #include <vector>
#include <iostream>
              
void solve() {
  std::string X, Y;
  std::cin >> X >> Y;
  const int LX = X.size();
  const int LY = Y.size();
  std::vector<int> dp0(LY+1, 0), dp1(LY+1, 0);
  std::vector<int> *dp = &dp0;
  std::vector<int> *dp_ = &dp1;
  for (int i = 1; i < LX+1; i++) {
    std::swap(dp, dp_);
    for (int j = 1; j < LY+1; j++) {
      (*dp)[j] = std::max((*dp)[j-1], (*dp_)[j]);
      if (X[i-1] == Y[j-1]) {
        (*dp)[j] = std::max((*dp)[j], (*dp_)[j-1] + 1);
      }       
    }         
  }           
  std::cout << dp->back() << std::endl;
}             
              
int main() {  
  int N;      
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    solve();  
  }           
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 1000


int lcs(std::string X, std::string Y) {
    int c[MAX+1][MAX+1];
    int maxl = 0;
    int m = X.size();
    int n = Y.size();
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 0;
    }
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = std::max(c[i-1][j], c[i][j-1]);
            }
            maxl = std::max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    std::string s1, s2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::cin >> s1 >> s2;
        int a = lcs(s1, s2);
        printf("%d\n", lcs(s1, s2));
    }
    
    return 0;
}