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 <stdio.h>
#include <string.h>

int cache[1001][1001];
const int INF = 1 << 20;

int max(int x, int y) { if (x < y) return y; else return x; }

int lcs(char *x, char *y, int xl, int yl) {
	if (cache[xl][yl] != INF) {
		return cache[xl][yl];
	}
	if (xl == 0 || yl == 0) return 0;
	if (x[xl-1] == y[yl-1]) {
		return cache[xl][yl] = lcs(x, y, xl - 1, yl - 1) + 1;
	} else {
		return cache[xl][yl] = max(lcs(x, y, xl - 1, yl), lcs(x, y, xl, yl - 1));
	}
}

int main(void) {
	int q;
	scanf("%d\n", &q);
	for (int i = 0; i < q; i ++) {
		char X[1000];
		char Y[1000];
		for (int i = 0; i <= 1000; i ++) {
			for (int j = 0; j <= 1000; j ++) {
				cache[i][j] = INF;
			}
		}
		gets(X);
		gets(Y);
		printf("%d\n", lcs(X, Y, strlen(X), strlen(Y)));
	}
	return 0;
}

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

int main(){
  int n;
  std::cin>>n;
  int B[1500]={0};
  for(int k=0;k<n;k++){
    std::string str1;
    std::string str2;
    std::cin>>str1;
    std::cin>>str2;
    int A[1000][1000]={0};
    /*初期化？*/
    for(int i=0;i<str1.size();i++){
      if(str1[i]==str2[0]){
	A[i][0]=1;
      }
      if(i>0){
	A[i][0]=std::max(A[i][0],A[i-1][0]);
      }
    }
    for(int j=0;j<str2.size();j++){
      if(str1[0]==str2[j]){
	A[0][j]=1;
      }
      if(j>0){
	A[0][j]=std::max(A[0][j],A[0][j-1]);
      }
    }
    for(int i=1;i<str1.size();i++){
      for(int j=1;j<str2.size();j++){
	if(str1[i]==str2[j]){
	  A[i][j]=A[i-1][j-1]+1;
	}else{
	  A[i][j]=std::max(A[i-1][j],A[i][j-1]);
	}
      }
    }
    B[k]=A[str1.size()-1][str2.size()-1];
  }
  for(int i=0;i<n;i++){
    std::cout<<B[i]<<"\n";
  }
  return 0;
}

C++: // 17D8104010B 宮本拓輝 10_c c++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int score[1001][1001];
  int n;
  cin>>n;
  int result[n];
  for(int s=0;s<n;s++){
    string x,y;
    cin>>x;
    cin>>y;

    for(int i=0;i<x.size();i++){
      for(int j=0;j<y.size();j++){
        if(x[i]==y[j]){
          score[i+1][j+1]=score[i][j]+1;
        }
        else{
          score[i+1][j+1]=max(score[i+1][j],score[i][j+1]);
        }
      }
    }
    //cout<<score[x.size()][y.size()]<<"\n";
    result[s]=score[x.size()][y.size()];

  }
  for(int i=0;i<n;i++){
    cout<<result[i]<<"\n";
  }

  return 0;
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL][MAXL];

int lec(string X,string Y)
{
    int XL = X.length();
    int YL = Y.length();
    for(int i=0;i<XL;i++)
        C[i][0] = 0;
    for(int i=0;i<YL;i++)
        C[0][i] = 0;
    for(int i=0;i<XL;i++)
    {
        for(int j=0;j<YL;j++)
        {
            if(X[i]==Y[j])
            {
                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];
            }
        }
    }
    return C[XL-1][YL-1];
}

int main()
{
    int q;
    string x,y;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        cout<<lec(x,y)<<endl;
    }
    return 0;
}

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

const int MAX_X = 1000, MAX_Y = 1000;

int main() {
  int n;
  int dp[MAX_X+1][MAX_Y+1];
  string X, Y;
  cin >> n;
  for (int k=0; k<n; k++) {
    cin >> X >> Y;
    for (int i=0; i<=X.length(); i++) {
      for (int j=0; j<=Y.length(); j++) {
        dp[i][j] = 0;
      }
    }

    for (int i=1; i<=X.length(); i++) {
      for (int j=1; j<=Y.length(); j++) {
        if (X[i-1] == Y[j-1]) {
          dp[i][j] = dp[i-1][j-1] + 1;
        } else {
          dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
      }
    }

    cout << dp[X.length()][Y.length()] << endl;
  }
  return 0;
}

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

string X, Y;
int lc[1005][1005];

int getLCS(int m, int n) {
	if (m < 0 || n < 0)
		return 0;
	if (lc[m][n] != -1)
		return lc[m][n];
	if (X[m] == Y[n]) 
		return lc[m][n] = getLCS(m - 1, n - 1) + 1;
	else
		return lc[m][n] = max(getLCS(m, n - 1), getLCS(m - 1, n));
}

int main(void) {
	int i, j;
	int nu;
	cin >> nu;
	while (nu--) {
		for (i = 0; i < 1005; i++) 
			for (j = 0; j < 1005; j++) 
				lc[i][j] = -1;
		cin >> X >> Y;
		int m = X.length() - 1, n = Y.length() - 1;
		int lcs = getLCS(m, n);
		cout << lcs << endl;
	}
}

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

typedef long long llong;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int q;
	cin >> q;
	while (q--) {
		string a, b;
		cin >> a >> b;
		int n = a.length(), m = b.length();
		vector<int> prev(m + 1, 0);
		for (int i = 1; i <= n; ++i) {
			vector<int> current(m + 1);
			current[0] = 0;
			for (int j = 1; j <= m; ++j) {
				if (a[i - 1] == b[j - 1]) {
					current[j] = 1 + prev[j - 1];
				} else {
					current[j] = max(current[j - 1], prev[j]);
				}
			}
			prev = current;
		}
		cout << prev[m] << '\n';
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int dp[1000][1000];

int main() {
  int q;
  cin >> q;
  REP(loop, q) {
    char S[1000], T[1000];
    cin >> S >> T;

    dp[0][0] = 0;
    for (int i = 1; i <= strlen(S); i++) {
      for (int j = 1; j <= strlen(T); 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[strlen(S)][strlen(T)] << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define N 10000

int lcs(char *x,char *y){
	int c[N+1][N+1];
	int m = strlen(x);
	int n = strlen(y);
	int maxl = 0;
	x = strcat(" ",x);
	y = strcat(" ",y);
	int i,j;
	for(i=1;i<=m;i++){
		c[i][0]=0;
	}
	for(j=0;j<=n;j++){
		c[0][j]=0;
	}

	for(i = 1;i<=m;i++){
		for(j=1;j<=n;j++){
			if(x[i]==y[j]){
				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(maxl>c[i][j])maxl = maxl;
			else maxl = c[i][j];
		}
	}
	return maxl;
}

int main(){
	char s1[1000];
	char s2[1000];
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++){
		scanf("%s%s",s1,s2);
		printf("%d\n",lcs(s1,s2));
	}
	return 0;
}