SHARE
TWEET

Untitled

a guest Feb 19th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     freopen("input.txt", "r", stdin);
  6.     freopen("output.txt", "w", stdout);
  7.     int a, i, n, m, z;
  8.     cin >> n >> m;
  9.     int* arr1 = new int[n];
  10.     int* arr2 = new int[m];
  11.     for (i = 0; i < n; i++)
  12.         cin >> arr1[i];
  13.     for (i = 0; i < m; i++)
  14.         cin >> arr2[i];
  15.     if (n > m)
  16.         z = n + 1;
  17.     else
  18.         z = m + 1;
  19.     int* arr3 = new int[z];
  20.     arr3[0] = arr1[n - 1];
  21.     i = 1;
  22.     while (n - i > 0) {
  23.         arr3[i] = arr1[n - i - 1];
  24.         i = i + 1;
  25.     }
  26.     arr3[0] += arr2[m - 1];
  27.     arr3[1] += arr3[0] / 10;
  28.     arr3[0] = arr3[0] % 10;
  29.     i = 1;
  30.     while (m - i > 0) {
  31.         arr3[i] += arr2[m - i - 1];
  32.         arr3[i + 1] += arr3[i] / 10;
  33.         arr3[i] = arr3[i] % 10;
  34.         i = i + 1;
  35.     }
  36.     if (arr3[z - 1] > 0)
  37.         for (i = z - 1; i >= 0; i--)
  38.             cout << arr3[i];
  39.     else
  40.         for (i = z - 2; i >= 0; i--)
  41.             cout << arr3[i];
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top