#include <bits/stdc++.h>
using namespace std;
string a, b, c, d, w;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
if (a.length() >= b.length())
{
c = a;
for (int i = 0; i < a.length()-b.length(); i++)
d += '0';
d += b;
}
else
{
c = b;
for (int i = 0; i < b.length()-a.length(); i++)
d += '0';
d += a;
}
//cout << a << "\n" << b;
int r = 0, x, y, s;
for (int i = c.length()-1; i >= 0; i--)
{
x = int(c[i])-48, y = int(d[i])-48;
s = x+y+r;
w += char(s%10 + 48);
if (s >= 10)
r = 1;
else
r = 0;
}
reverse(w.begin(), w.end());
if (r)
cout << '1';
cout << w;
exit(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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <bits/stdc++.h> using namespace std; string a, b, c, d, w; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b; if (a.length() >= b.length()) { c = a; for (int i = 0; i < a.length()-b.length(); i++) d += '0'; d += b; } else { c = b; for (int i = 0; i < b.length()-a.length(); i++) d += '0'; d += a; } //cout << a << "\n" << b; int r = 0, x, y, s; for (int i = c.length()-1; i >= 0; i--) { x = int(c[i])-48, y = int(d[i])-48; s = x+y+r; w += char(s%10 + 48); if (s >= 10) r = 1; else r = 0; } reverse(w.begin(), w.end()); if (r) cout << '1'; cout << w; exit(0); } |
English