Go: package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;int l(string a,string b){int m=a.size(),n=b.size(),i=0,j,s=0,c[1001][1001]={};for(a=' '+a,b=' '+b;++i<=m;)for(j=0;++j<=n;s=s<c[i][j]?c[i][j]:s)c[i][j]=a[i]==b[j]?c[i-1][j-1]+1:c[i-1][j]>c[i][j-1]?c[i-1][j]:c[i][j-1];return s;}main(){string a,b;int n;for(cin>>n;n--;)cin>>a>>b,cout<<l(a,b)<<endl;}

C++: using namespase 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 = 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[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 ( i = 0; i < n; i++ ){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << sndl;
    }
    
    return 0;
    
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int lcs(string x, string y) {
    static int c[1001][1001];
    int m = x.size();
    int n = y.size();
    int max1 = 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[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]);
            max1 = max(max1, c[i][j]);
 
        }
    }
    return max1;
}
 
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 <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int MAX = 1001;
int L[MAX][MAX];

int LCS(string s1, string s2)
{
    int m = s1.size();
    int n = s2.size();
    for (int i = 0; i <= m; ++i)
    {
        L[i][0] = 0;
    }
    for (int i = 0; i <= n; ++i)
    {
        L[0][i] = 0;
    }
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (s1[i-1] == s2[j-1])
            {
                L[i][j] = L[i-1][j-1] + 1;
            }
            else
            {
                L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        }
    }
    return L[m][n];
}

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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
int dp[1001][1001];
//?????????????????????
int n;
string x,y;
void solve(){
	cin >> n;
	REP(j,n){
	cin >> x >> y;
	memset(dp,0,1001*1001);
	int xn = x.size();
	int yn = y.size();
	REP(jj,xn+1){
		 REP(ii,yn+1){
			 if(jj <= 0 || ii <= 0){
				 dp[jj][ii] = 0 ;
			 }
			 else if(x[jj-1]==y[ii-1]) {
				 dp[jj][ii] = 1 + dp[jj-1][ii-1];
			 }
			 else{
				 dp[jj][ii] = max ( dp[jj-1][ii], dp[jj][ii-1] );
		   }
			 //cout << '('<<ii<<','<<jj<<')'<<dp[jj][ii]<<endl;
		 }

	}
	cout << dp[xn][yn]<<endl;
	}


}


int main(){
solve();
}

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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

#define PB push_back
#define SZ(x) ((int)(x).size())

using namespace std;

typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<int> > VVi;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }

int n;
Vs vs, vt;

int main()
{
	cin >> n;
	REP(_i, n)
	{
		string s, t;
		cin >> s >> t;
		vs.PB(s);
		vt.PB(t);
	}

	REP(_i, n)
	{
		string& s = vs[_i];
		string& t = vt[_i];
		
		VVi dp(SZ(s) + 1, Vi(SZ(t) + 1, 0));

		REP(i, SZ(s))
			REP(j, SZ(t))
		{
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
			if (s[i] == t[j])
				chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		}

		cout << dp[SZ(s)][SZ(t)] << endl;
	}


}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int dp[1001][1001] = {};

int getLCS(string X, string Y)
{
    int m = 0;
    for (int i = 1; i <= X.size(); i++)
    {
        for (int j = 1; j <= Y.size(); j++)
        {
            dp[i][j] = X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]);
            m = max(m, dp[i][j]);
        }
    }
    return m;
}

int main()
{
    int q;
    string X, Y;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> X >> Y;
        cout << getLCS(X, Y) << "\n";
    }
    return 0;
}

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

using namespace std;
int n;

int main(void){
    // Your code here!
    string S, T;
    int dp[1001][1001];
    cin >> n;
    for(int c = 0; c < n; c++){
        cin >> S >> T;
        
        for(int i = 0; i <= S.size(); i++){
            dp[i][0] = 0;
        }
        for(int j = 0; j <= T.size(); j++){
            dp[0][j] = 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] = max({dp[i][j] + 1, dp[i][j+1], dp[i+1][j]});
                else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
        
        cout << dp[S.size()][T.size()] << endl;
    }
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[1001][1001];
  
  while (flag == 0)
  {
    if (x[xn] >= 97 && x[xn] <= 122)
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] >= 97 && y[yn] <= 122)
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 1; j++)
    {
      if (x[i - 1] == y[j - 1])
      {
        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 (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}