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 <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll
//
//vector<int> G[20];
//
//// 巡回セールスマン問題
//
//signed main(){
//  int v,e;
//  cin>>v>>e;
//
//  for(int i=0; i<e; i++){
//    int a,b;
//    cin>>a>>b;
//    G[a].push_back(b);
//  }
//}























////  最長共通部分列

int dp[1005][1005];

signed main(){
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    string s1,s2;
    cin>>s1>>s2;
    s1=" "+s1;
    s2=" "+s2;
    int maxl=0;
    for(int i=0; i<=s1.size()-1; i++) for(int j=0; j<=s2.size(); j++) dp[i][j]=0;
    for(int i=1; i<=s1.size()-1; i++){
      for(int j=1; j<=s2.size(); j++){
        if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        maxl=max(maxl,dp[i][j]);
      }
    }
    cout<<maxl<<en;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int c[1010][1010];
int lcs(string x,string y){
    int m = x.size();
    int n = y.size();
    int maxl;
    for (int i=1; i<=m; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=n;j++){
        c[0][j] = 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] = max(c[i-1][j], c[i][j-1]);
            maxl = max(maxl, c[i][j]);
        }
        
    }
    return maxl;
}
int main(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

C++: #include <iostream>
#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.length();
    int n = Y.length();

    X = ' ' + X;
    Y = ' ' + Y;
    
    int maxl = 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() {
    int n;
    string X, Y;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> X >> Y;
        lcs(X, Y);
    }
        
    return 0;
}

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

using namespace std;

string s1, s2;

int lcs() {
  int i, j, flag = 0;
  int dp[s1.length()+1][s2.length()+1] = {};
  
  for(i = 1; i <= s1.length(); i++) {
    for(j = 1; j <= s2.length(); j++) {
      dp[i][j] = max(max(dp[i-1][j-1], dp[i-1][j]), dp[i][j-1]);
      if(s1[i-1] == s2[j-1] && flag == 0) { 
	dp[i][j]++;
	flag++;
      }
      //      cout << dp[i][j] << ' ';
    }
    //    cout << endl;
    flag = 0;
  }
  return dp[s1.length()][s2.length()];
}

int main(){
  int n;
  cin >> n;
  while(n--) {
    cin >> s1 >> s2;
    cout << lcs() << endl;
  }
  
  return 0;
}

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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int solve() {

  string s, t;
  cin >> s >> t;

  // dp[i][j] := s_1,...s_i と t_1,...t_j に対するLCSの長さ
  // s[i] == t[j] なら dp[i-1][j-1] + 1
  // s[i] != t[j] なら max( dp[i-1][j], dp[i][j-1] )
  int dp[s.size()+1][t.size()+1];
  fill(dp[0], dp[s.size()+1], 0);
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < t.size(); 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]);
      }
    }
  }

  return dp[s.size()][t.size()];


}


int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  for(int i = 0; i < N; i++) {
    cout << solve() << "\n";
  }


  return 0;
}

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;
  
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (X[i] == Y[j]) 
        if (i == 0 || j == 0) 
          c[i][j] = 1;
        else 
          c[i][j] = c[i - 1][j - 1] + 1;
      else
        if (i != 0 && j != 0) 
          c[i][j] = max(c[i][j - 1], c[i - 1][j]);
        else
          c[i][j] = 0;
      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;
}