-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·71 lines (60 loc) · 1.24 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·71 lines (60 loc) · 1.24 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
#include <bits/stdc++.h>
using namespace std;
void remove_leading_zeros(string &s)
{
int i = 0;
for (; i < s.length(); ++i)
{
if (s[i] != '0')
break;
}
if (i == s.length())
s = "0";
else
s = s.substr(i);
}
int main()
{
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
string result_a, result_b;
for (int i = 0; i < max(a.length(), b.length()); ++i)
{
if (i > a.length())
a += '0';
if (i > b.length())
b += '0';
if (a[i] == b[i])
{
result_a += a[i];
result_b += b[i];
}
else if (a[i] < b[i])
{
result_b += b[i];
}
else
{
result_a += a[i];
}
}
reverse(result_a.begin(), result_a.end());
reverse(result_b.begin(), result_b.end());
if (result_a.length() == 0)
cout << "YODA" << endl;
else
{
remove_leading_zeros(result_a);
cout << result_a << endl;
}
if (result_b.length() == 0)
cout << "YODA" << endl;
else
{
remove_leading_zeros(result_b);
cout << result_b << endl;
}
return 0;
}