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 proverka (int *a, int *b, int n)
- {
- int znach = 0;
- for (int i =0; i < n; i++)
- {
- if (a[i] > b[i])
- {
- znach = 1;
- break;
- }
- if (a[i] < b[i])
- {
- znach = -1;
- break;
- }
- }
- return znach;
- }
- int main()
- {
- int n, m, f, parametr = 0;
- cin >> n >> m;
- int s = n-1, c = m-1;
- 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];
- if (m == n)
- parametr = proverka(a, b, n);
- if (n > m || ( n == m && parametr == 1))
- minuss(a, b, n, m, n);
- else if (m > n || (n == m && parametr == -1))
- {
- cout << "-";
- minuss(b, a, m, n, m);
- }
- else if (m == n && parametr == 0)
- cout << 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement