Advertisement
Guest User

uva424

a guest
Apr 6th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. #include<stdio.h>
  4. using namespace std;
  5.  
  6. typedef long long int ll;
  7. typedef char ch;
  8.  
  9. int main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.  
  14.     ll r,a,b,i,j,st1,st2,sm;
  15.     ch s[100],ans[400];
  16.     memset(ans,'0',400);
  17.  
  18.     st2=1;
  19.  
  20.     while(1)
  21.     {
  22.         r=0;
  23.         cin>>s;
  24.         if(!strcmp(s,"0"))
  25.             break;
  26.         st1=strlen(s);
  27.         r=0;
  28.         for(i=st1-1,j=0;i>=0;j++,i--)
  29.         {
  30.             a=s[i]-'0';
  31.             b=ans[j]-'0';
  32.  
  33.             sm=a+b+r;
  34.             r=sm/10;
  35.             sm%=10;
  36.             ans[j]=sm+'0';
  37.         }
  38.         while(r>0)
  39.         {
  40.             a=ans[j]-'0';
  41.             sm=a+r;
  42.             r=sm/10;
  43.             sm%=10;
  44.             ans[j]=sm+'0';
  45.             j++;
  46.         }
  47.         if(j>st2)
  48.             st2=j;
  49.  
  50.         printf("%d\n",st2);
  51.  
  52.         for(i=st2-1;i>=0;i--)
  53.             printf("%c",ans[i]);
  54.         printf("\n");
  55.     }
  56.         //st2=strlen(ans);
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement