Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void minuss (int *a, int *b, int n, int m, int f)
- {
- int l = f-1, s = n-1, c = m-1, times = s;
- int *result = new int[f];
- while(s > 0 && c > 0)
- {
- if (a[s] - b[c] < 0)
- {
- times = s-1;
- a[s] += 10;
- while (a[times] == 0)
- {
- a[times] += 9;
- times--;
- }
- a[times]--;
- }
- result[l] = a[s] - b[c];
- l--;
- s--;
- c--;
- }
- if (s >= 0 && c == 0)
- {
- if (a[s] - b[c] < 0)
- {
- times = s-1;
- a[s] += 10;
- while (a[times] == 0)
- {
- a[times] += 9;
- times--;
- }
- a[times]--;
- }
- result[l] = a[s] - b[c];
- l--;
- s--;
- c--;
- }
- while (s >= 0)
- {
- result[l] = a[s];
- l--;
- s--;
- }
- int index = 0;
- while (result[index] == 0)
- index++;
- for (int i = index; i < f; i++)
- cout << result[i];
- }
- int main()
- {
- int n, m;
- cin >> n >> m;
- int *a = new int[n];
- for ( int i = 0; i < n; i++)
- cin >> a[i];
- int *b = new int[m];
- for (int i =0; i < m; i++)
- cin >> b[i];
- minuss(a, b, n, m, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement