-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstract.cpp
More file actions
58 lines (45 loc) · 760 Bytes
/
substract.cpp
File metadata and controls
58 lines (45 loc) · 760 Bytes
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string a, b;
getline(cin, a);
getline(cin, b);
vector <int> x;
vector <int> y;
for (int i = a.size() - 1; i >= 0; i--)
{
x.push_back(a[i] - '0');
}
for (int i = b.size() - 1; i >= 0; i--)
{
y.push_back(b[i] - '0');
}
for (int i = 0; i < a.size() - b.size(); i++)
{
y.push_back(0);
}
vector<int> r;
for (int i = 0; i < x.size(); i++)
{
int t = 0;
if (x[i] >= y[i]) t = x[i] - y[i];
else
{
t = 10 + x[i] - y[i];
x[i + 1]--;
}
r.push_back(t);
}
int i = r.size() - 1;
while (r[i] == 0) i--;
while (i >= 0)
{
cout << r[i];
i--;
}
cout << endl;
return 0;
}