Language: C++

int main(void) {
    string s, t;
    cin >> s >> t;
    s.push_back('A');
    t.push_back('B');
    // dp[i][j] contains the length of the longest subsequence if s from s_0..s_i
    // and t from t_0..t_j
    vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
    for (int i = 0; i < (int)s.size(); i++) {
        for (int j = 0; j < (int)t.size(); j++) {
            if (s[i] == t[j]) {
                if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < 1 + dp[i][j].first) {
                    dp[i + 1][j + 1] = { 1 + dp[i][j].first, {i, j} };
                }
            }
            else {
                if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < dp[i][j].first) {
                    dp[i + 1][j + 1] = dp[i][j];
                }
                if (i + 1 < (int)dp.size() && dp[i + 1][j].first < dp[i][j].first) {
                    dp[i + 1][j] = dp[i][j];
                }
                if (j + 1 < (int)dp[0].size() && dp[i][j + 1].first < dp[i][j].first) {
                    dp[i][j + 1] = dp[i][j];
                }
            }
        }
    }

    string ans;
    int index_s = s.size() - 1, index_t = t.size() - 1;
    while (index_s != -1) {
        ans.push_back(s[index_s]);
        int a = index_s, b = index_t;
        auto x = dp[a][b];
        index_s = x.second.first, index_t = x.second.second;
    }
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    cout << ans << '\n';
}

Compiler output:
a.cc: In function 'int main()':
a.cc:2:5: error: 'string' was not declared in this scope
    2 |     string s, t;
      |     ^~~~~~
a.cc:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> s >> t;
      |     ^~~
a.cc:3:12: error: 's' was not declared in this scope
    3 |     cin >> s >> t;
      |            ^
a.cc:3:17: error: 't' was not declared in this scope
    3 |     cin >> s >> t;
      |                 ^
a.cc:8:5: error: 'vector' was not declared in this scope
    8 |     vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
      |     ^~~~~~
a.cc:8:21: error: 'pair' was not declared in this scope
    8 |     vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
      |                     ^~~~
a.cc:8:27: error: expected primary-expression before 'int'
    8 |     vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
      |                           ^~~
a.cc:8:126: error: expected primary-expression before ')' token
    8 |     vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
      |                                                                                                                              ^
a.cc:12:34: error: 'dp' was not declared in this scope
   12 |                 if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < 1 + dp[i][j].first) {
      |                                  ^~
a.cc:17:34: error: 'dp' was not declared in this scope
   17 |                 if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < dp[i][j].first) {
      |                                  ^~
a.cc:20:34: error: 'dp' was not declared in this scope
   20 |                 if (i + 1 < (int)dp.size() && dp[i + 1][j].first < dp[i][j].first) {
      |                                  ^~
a.cc:23:34: error: 'dp' was not declared in this scope
   23 |                 if (j + 1 < (int)dp[0].size() && dp[i][j + 1].first < dp[i][j].first) {
      |                                  ^~
a.cc:30:11: error: expected ';' before 'ans'
   30 |     string ans;
      |           ^~~~
      |           ;
a.cc:33:9: error: 'ans' was not declared in this scope
   33 |         ans.push_back(s[index_s]);
      |         ^~~
a.cc:34:30: error: 'index_t' was not declared in this scope; did you mean 'index_s'?
   34 |         int a = index_s, b = index_t;
      |                              ^~~~~~~
      |                              index_s
a.cc:35:18: error: 'dp' was not declared in this scope
   35 |         auto x = dp[a][b];
      |                  ^~
a.cc:38:13: error: 'ans' was not declared in this scope
   38 |     reverse(ans.begin(), ans.end());
      |             ^~~
a.cc:38:5: error: 'reverse' was not declared in this scope
   38 |     reverse(ans.begin(), ans.end());
      |     ^~~~~~~
a.cc:40:5: error: 'cout' was not declared in this scope
   40 |     cout << ans << '\n';
      |     ^~~~