Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //freopen ("10035.in", "r", stdin);
  7.     //freopen ("10035.out", "w", stdout);
  8.     string str1, str2;
  9.     int a, b, i, arr1[12]={0}, arr2[12]={0}, count = 0, size;
  10.  
  11.     while (cin >> str1 >> str2)
  12.     {
  13.         if (str1 == "0" && str2 == "0")
  14.         {
  15.             cout<<endl;
  16.             break;
  17.         }
  18.         else
  19.         {
  20.  
  21.             for (i = 10; i > 10  - str1.size(); i--)
  22.             {
  23.                 arr1[i] = str1[10-i] - '0';
  24.             }
  25.             for (i = 10; i >10- str2.size(); i--)
  26.             {
  27.                 arr2[i] = str2[10 - i] - '0';
  28.             }
  29.             size = str1.size();
  30.             if (size < str2.size())
  31.             {
  32.                 size = str2.size();
  33.             }
  34.             count=0;
  35.             for (int k = 0; k <10; k++)
  36.             {
  37.                 if (arr1[k] + arr2[k] > 9)
  38.                 {
  39.                     count = count + 1;
  40.                     arr1[k + 1]=arr1[k+1]+1;
  41.                 }
  42.             }
  43.             if (count == 1)
  44.             {
  45.                 cout << "1 carry operation." << endl;
  46.             }
  47.             else if(count == 0)
  48.             {
  49.                 cout<<"No carry operation."<<endl;
  50.             }
  51.             else
  52.             {
  53.                 cout << count << " carry operations." << endl;
  54.             }
  55.         }
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement