Language: C++

#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;

string A, B, C;

ll solve1() {
    if (A[0] == '?' && B[0] == '?') {
        int cnt = 0;
        if (C[0] == '?') {
            for (size_t i = 1; i < 10; i++) {
                for (size_t j = 1; j < 10; j++) {
                    if (i + j < 10) ++cnt;
                }
            }
        } else {
            for (size_t i = 1; i < 10; i++) {
                for (size_t j = 1; j < 10; j++) {
                    if (i + j == C[0] - '0') ++cnt;
                }
            }
        }
        return cnt;
    }
    else if(A[0] == '?' || B[0] == '?') {
        if (A[0] == '?') swap(A[0], B[0]);
        if (C[0] == '?') {
            int d = C[0] - A[0];
            if (d <= 0) return 0;
            else return 9 - (A[0] - '0');
        } else {
            if (C[0] - '0' - A[0] - '0' > 0) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    else {
        if (C[0] == '?') {
            int x = A[0] - '0' + B[0] - '0';
            return 0 < 1 && x < 10;
        } else {
            return A[0] - '0' + B[0] - '0' == C[0] - '0';
        }
    }
}

int main() {
    while (cin >> A, A != "0") {
        cin >> B >> C;

        reverse(A.begin(), A.end());
        reverse(B.begin(), B.end());
        reverse(C.begin(), C.end());

        int n = B.size();
        
        if (n == 1) {
            cout << solve1() << endl;
            continue;
        } 
        
        ll dp[55][2] = { 0 };

        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                int q = 0, s = 0, t = 0;
                if (A[i] == '?') q++;
                else s += A[i] - '0';
                if (B[i] == '?') q++;
                else s += B[i] - '0';
                if (C[i] != '0') t = C[i] - '0';
                if (q == 2) {
                    for (int a = 0; a <= 9; a++) {
                        if (i == n - 1 && a == 0) continue;
                        for (int b = 0; b <= 9; b++) {
                            if (i == n - 1 && b == 0) continue;
                            if (i == n - 1 && (t == 0 || (a + b + j) % 10 == 0)) continue;
                            if ((C[i] == '?' || (a + b + j) % 10 == t)) {
                                if (a + b + j >= 10) {
                                    (dp[i + 1][1] += dp[i][j]) %= MOD;
                                } else {
                                    (dp[i + 1][0] += dp[i][j]) %= MOD;
                                }
                            }
                        }
                    }
                } else if (q == 1) {
                    for (int a = 0; a <= 9; a++) {
                        if (i == n - 1 && a == 0) continue;
                        if ((i == n - 1 && (s + a + j) % 10 == 0)) continue;
                        if (C[i] == '?' || (s + a + j) % 10 == t) {
                            if (s + a + j >= 10) {
                                (dp[i + 1][1] += dp[i][j]) %= MOD;
                            } else {
                                (dp[i + 1][0] += dp[i][j]) %= MOD;
                            }
                        }
                    }
                } else { // q == 0
                    if ((i == n - 1 && (s + j) % 10 == 0)) continue;
                    if (C[i] == '?' || (s + j) % 10 == t) {
                        if ((s + j) >= 10) {
                            (dp[i + 1][1] += dp[i][j]) %= MOD;
                        } else {
                            (dp[i + 1][0] += dp[i][j]) %= MOD;
                        }
                    }
                }
            }// for j
        }// for i
        cout << dp[n][0] << endl;
    }// while
}// main

Compiler output:
a.cc: In function 'int main()':
a.cc:55:9: error: 'reverse' was not declared in this scope
   55 |         reverse(A.begin(), A.end());
      |         ^~~~~~~