-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·84 lines (62 loc) · 1.41 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·84 lines (62 loc) · 1.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#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';
result += (char)((_a + _b + carry) % 10) + '0';
carry = (_a + _b + carry) / 10;
}
if (carry)
{
result += (carry + '0');
}
reverse(result.begin(), result.end());
return {result};
}
};
int main()
{
string s_a, s_b;
char op;
cin >> s_a >> op >> s_b;
if (op == '*')
{
int zeroes = 0;
string c = s_a + s_b;
for_each(c.begin(), c.end(),
[&](const char c)
{
if (c == '0')
++zeroes;
});
cout << "1";
for (int i = 0; i < zeroes; ++i)
cout << "0";
cout << endl;
}
else
{
big_integer a, b;
a.v = s_a;
b.v = s_b;
big_integer c = a + b;
cout << c.v << endl;
}
return 0;
}