Advertisement
YEZAELP

THACO: easy

Nov 3rd, 2020
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. char ar1[100010], ar2[100010];
  6. vector <int> A, B, ans;
  7. int main(){
  8.  
  9.     int l;
  10.  
  11.     scanf("%s", ar1);
  12.     l = strlen(ar1);
  13.     for(int i=l-1;i>=0;i--){
  14.         A.push_back(ar1[i] - '0');
  15.     }
  16.  
  17.     scanf("%s", ar2);
  18.     l = strlen(ar2);
  19.     for(int i=l-1;i>=0;i--){
  20.         B.push_back(ar2[i] - '0');
  21.     }
  22.  
  23.     while(A.size() != B.size()){
  24.         if(A.size() < B.size()) A.push_back(0);
  25.         else B.push_back(0);
  26.     }
  27.  
  28.     int sz = A.size();
  29.     int r = 0;
  30.     for(int i=0;i<sz;i++){
  31.         int x = A[i] + B[i] + r;
  32.         if(x < 10) ans.push_back(x);
  33.         else ans.push_back(x%10);
  34.         r = x / 10;
  35.     }
  36.     if(r != 0) ans.push_back(r);
  37.  
  38.     for(int i = ans.size()-1; i >= 0; i--) printf("%d", ans[i]);
  39.  
  40.     return 0;
  41. }
  42.  
Advertisement
RAW Paste Data Copied
Advertisement