Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n=0, m=0, c=0, f=0;
- cin >> n >> m;
- int *arr, *ar;
- arr = new int[n];
- ar = new int[m];
- for (int i=0; i<n; i++)
- cin >> arr[i];
- for (int j=0; j<m; j++)
- cin >> ar[j];
- if (n>=m)
- f=n+1;
- else f=m+1;
- int res[f];
- int k=n-1;
- int j=m-1;
- int l=f-1;
- for (int x=0; x<f; x++)
- res[x]=0;
- while (k>=0 && j>=0)
- {
- c = arr[k]+ar[j]+res[l];
- if (c>=10)
- {
- res[l]=c%10;
- res[l-1]+=c/10;
- }
- else
- res[l]=c;
- k--;
- j--;
- l--;
- }
- while (k>=0)
- {
- c = arr[k]+res[l];
- if (c>=10)
- {
- res[l]=c%10;
- res[l-1]+=c/10;
- }
- else
- res[l]=c;
- k--;
- l--;
- }
- while (j>=0)
- {
- c = ar[j]+res[l];
- if (c>=10)
- {
- res[l]=c%10;
- res[l-1]+=c/10;
- }
- else
- res[l]=c;
- j--;
- l--;
- }
- if (res[0]!=0)
- for (int i=0; i<f; i++)
- cout << res[i];
- else
- for (int i=1; i<f; i++)
- cout << res[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement