-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path076.cpp
92 lines (70 loc) · 1.24 KB
/
076.cpp
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
85
86
87
88
89
90
91
92
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
//#include <cmath>
//#include <climits>
//#include <string>
//#include <algorithm>
using namespace std;
int Sub(int a[], int b[], int n, int m) {
int *c = new int[n];
int num1, num2, k = 0;
for (int i = n - 1; i >= 0; i--) {
num1 = a[i];
if (m - 1 - k >= 0 && m - 1 - k < m)
num2 = b[m - 1 - k];
else
num2 = 0;
if (num1 < num2) {
num1 = num1 + 10;
a[i - 1] = a[i - 1] - 1;
}
c[i] = num1 - num2;
k++;
}
bool tag = false;
for (int i = 0; i < n; i++) {
if (i == 0 && c[i] == 0) {
tag = true;
continue;
}
else if (tag) {
if (c[i] == 0 && i != n-1)
continue;
}
cout << c[i];
tag = false;
}
return 0;
}
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
int *a = new int[n];
int *b = new int[m];
bool tag = false;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
if (n > m)
Sub(a, b, n, m);
else if (n == m) {
for (int i = 0; i < n; i++) {
if (a[i] < b[i])
tag = true;
}
if (tag) {
cout << "-";
Sub(b, a, m, n);
}
else
Sub(a, b, n, m);
}
else {
cout << "-";
Sub(b, a, m, n);
}
return 0;
}