-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·63 lines (46 loc) · 1.23 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·63 lines (46 loc) · 1.23 KB
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;
struct big_integer
{
string v;
big_integer operator+(big_integer other)
{
string a = v;
string b = other.v;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if (a.length() < b.length())
swap(a, b);
string result;
int carry = 0;
for (int i = 0; i < a.length(); ++i)
{
if (i >= b.length())
b += '0';
int _a = a[i] - '0';
int _b = b[i] - '0';
// cout << _a << " + " << _b << " + " << carry << endl;
// cout << "mod: " << (_a + _b + carry) % 10 << endl;
// cout << "div: " << (_a + _b + carry) / 10 << endl;
result += (char)((_a + _b + carry) % 10) + '0';
carry = (_a + _b + carry) / 10;
// cout << " -- " << result << endl;
}
if (carry)
{
result += (carry + '0');
}
reverse(result.begin(), result.end());
return {result};
}
};
int main()
{
string a, b;
cin >> a >> b;
big_integer A = {a};
big_integer B = {b};
big_integer result = A + B;
cout << result.v << endl;
return 0;
}