Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int i=0,j,l=0,k,n=0,z,b,c=0,sum=0,carry=0,ans[1100];
- char p[1100],a[1100][1100];
- while(1)
- {
- cin>>p;
- k=strlen(p);
- if(p[0]=='0'&&k==1)
- break;
- if(k>n)
- n=k;
- strrev(p);
- strcpy(a[c],p);
- c++;
- }
- for(i=0;i<n;i++)
- {
- for(j=0;j<c;j++)
- if(a[j][i]<='9'&&a[j][i]>='0')
- {
- sum=sum+a[j][i]-48;
- }
- sum+=carry;
- k=sum%10;
- ans[l]=k;
- carry=sum/10;
- sum=0;
- l++;
- }
- if(carry!=0)
- {
- ans[l]=carry;
- l++;
- }
- int x=0;
- for(i=l-1;i>=0;i--)
- {
- if(ans[i]==0&&x==0)
- continue;
- else
- {
- cout<<ans[i];
- x++;
- }
- }
- if(x==0)
- cout<<"0";
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement