Пример #1
0
  private void borrow(int[] a, int initialPosition) {
    int borrowPosition = initialPosition + 1;
    if (a[borrowPosition] == 0) borrow(a, borrowPosition);

    a[initialPosition] += 10;
    --a[borrowPosition];
  }
Пример #2
0
  private int[] subtract(int[] a, int[] b) {
    int biggerSize = a.length;
    int smallerSize = b.length;

    int[] result = new int[biggerSize];
    for (int i = 0; i < smallerSize; ++i) {
      if (a[i] < b[i]) borrow(a, i);
      result[i] = a[i] - b[i];
    }

    int sizeDifference = biggerSize - smallerSize;
    if (sizeDifference > 0) System.arraycopy(a, smallerSize, result, smallerSize, sizeDifference);

    return result;
  }