Advertisement
Babul_420

uva 10013 Super long sums solution

Apr 4th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<math.h>
  3. #include<algorithm>
  4. using namespace std;
  5. int a1[2000000],a2[2000000],a3[2000000];
  6. int main()
  7. {
  8. long i,j,m,t,d,r;
  9. while(scanf("%ld",&t)==1)
  10. {
  11. for(i=0;i<t;i++)
  12.     {
  13.     scanf("%ld",&m);
  14.         {
  15.         for(j=0;j<m;j++)
  16.             {
  17.             scanf("%d%d",&a1[j],&a2[j]);
  18.             }
  19.         r=0;
  20.         for(j=m-1;j>=0;j--)
  21.             {
  22.             d=a1[j]+a2[j]+r;
  23.             if(d>9)
  24.                 {
  25.                 a3[j]=d%10;
  26.                 r=1;
  27.                 }
  28.             else
  29.                 {
  30.                 a3[j]=d;
  31.                 r=0;
  32.                 }
  33.             }
  34.         for(j=0;j<m;j++)
  35.         printf("%d",a3[j]);
  36.         printf("\n");
  37.         if(i!=t-1)
  38.         printf("\n");
  39.         }
  40.     }
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement