Language: C++

#include <bits/stdc++.h>

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VVVVI vector<vector<vector<vector<int>>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VVVVL vector<vector<vector<vector<LL>>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }
inline bool inside(int y, int x, int H, int W) { return 0 <= y and y < H and 0 <= x and x < W; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, 1, 0, -1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;

string big(string a, string b) {
    if (a.size() < b.size()) { return b; }
    if (a.size() > b.size()) { return a; }
    return a > b ? a : b;
}

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

    while (true) {
        int W, H;
        cin >> W >> H;
        if (W == 0 and H == 0) { break; }

        vector<vector<int>> field(H, vector<int>(W, -1));
        FOR(i, 0, H) {
            string s;
            cin >> s;
            FOR(j, 0, s.size()) {
                if (s[j] < 'A') {
                    field[i][j] = (s[j] - '0');
                }
            }
        }

        vector<vector<string>> dp(H, vector<string>(W));
        FOR(y, 0, H) {
            FOR(x, 0, W) {
                if (field[y][x] == -1) {
                    continue;
                }

                // 0 startはだめ
                if (dp[y][x].empty() and field[y][x] == 0) {
                    continue;
                }

                // start
                if (dp[y][x].empty()) {
                    dp[y][x] = to_string(field[y][x]);
                }

                if (y + 1 < field.size() and field[y + 1][x] != -1) {
                    string new_c = dp[y][x] + to_string(field[y + 1][x]);
                    dp[y + 1][x] = big(dp[y + 1][x], new_c);
                }
                if (x + 1 < field[0].size() and field[y][x + 1] != -1) {
                    string new_c = dp[y][x] + to_string(field[y][x + 1]);
                    dp[y][x + 1] = big(dp[y][x + 1], new_c);
                }
            }
        }

        string ans = "";
        FOR(y, 0, dp.size()) {
            FOR(x, 0, dp[0].size()) {
                ans = big(ans, dp[y][x]0;
            }
        }

        print(ans);
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:40: error: expected ')' before numeric constant
   93 |                 ans = big(ans, dp[y][x]0;
      |                          ~             ^
      |                                        )