Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int NMAX = 1000;
  5. int main(int argc,char* argv[]) {
  6.  
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. ///
  10. string a,b;
  11. cin >> a >> b;
  12. vector<int> A(NMAX,0),B(NMAX,0),C(NMAX,0),ANS(NMAX,0);
  13. int j = 0;
  14. for(int i = a.size() - 1; i >=0; i--) {
  15.     A[j] = a[i]-'0';
  16.     j++;
  17. }
  18. j = 0;
  19. for(int i = b.size() - 1; i >=0; i--) {
  20.     B[j] = b[i]-'0';
  21.     j++;
  22. }
  23.  
  24. for(int i = 0; i <= NMAX; i++){
  25.     int f;
  26.     int s = A[i] - B[i] - C[i];
  27.     if(s < 0){
  28.         ANS[i] = A[i] + 10 - B[i] - C[i];
  29.         C[i+1] = 1;
  30.     }
  31.     else ANS[i] = s;
  32. }
  33.  
  34. int f=NMAX;
  35. while(ANS[f] == 0){
  36. f--;   
  37. }
  38. if(f == -1){
  39.     cout << 0;
  40.     return 0;
  41. }
  42. for(int i = f; i >=0; i--) cout << ANS[i];
  43. ///
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement