#include <iostream>
#include <string>
#include <vector>
using namespace std;
using LL = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string a, b, c;
cin >> a >> b >> c;
int n = a.size();
vector<vector<LL>> dp(2, vector<LL>(n + 1));
for (int i = 0; i < n; ++i)
{
int da = a[i] - '0';
int db = b[i] - '0';
int dc = c[i] - '0';
int dab = da + db;
if (dab == dc)
dp[0][i + 1] = dp[0][i] + 1;
else if (dab + 1 == dc)
dp[1][i + 1] = dp[0][i] + 1;
else if (dab > 9 && dab - 10 == dc)
dp[0][i + 1] = dp[1][i];
else if (dab + 1 > 9 && dab + 1 - 10 == dc)
dp[1][i + 1] = dp[1][i];
}
LL res = 0;
for (int i = 1; i <= n; ++i)
{
res += dp[0][i];
}
cout << res << "\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <string> #include <vector> using namespace std; using LL = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string a, b, c; cin >> a >> b >> c; int n = a.size(); vector<vector<LL>> dp(2, vector<LL>(n + 1)); for (int i = 0; i < n; ++i) { int da = a[i] - '0'; int db = b[i] - '0'; int dc = c[i] - '0'; int dab = da + db; if (dab == dc) dp[0][i + 1] = dp[0][i] + 1; else if (dab + 1 == dc) dp[1][i + 1] = dp[0][i] + 1; else if (dab > 9 && dab - 10 == dc) dp[0][i + 1] = dp[1][i]; else if (dab + 1 > 9 && dab + 1 - 10 == dc) dp[1][i + 1] = dp[1][i]; } LL res = 0; for (int i = 1; i <= n; ++i) { res += dp[0][i]; } cout << res << "\n"; return 0; } |
English