Advertisement
Falak_Ahmed_Shakib

add 2 long int

Oct 3rd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*
  2. , \ / ,
  3. / \ )\__/( / \
  4. / \ (_\ /_) / \
  5. ____/_____\__\@ @/___/_____\____
  6. | |\../| |
  7. | \VV/ |
  8. | ------___------- |
  9. |__________Chuta Dragon___________|
  10. | /\ / \\ \ /\ |
  11. | / V )) V \ |
  12. |/ ` // ' \|
  13. ` V '
  14. */
  15. #include<bits/stdc++.h>
  16. using namespace std;
  17. typedef long long ll;
  18. int main()
  19. {
  20. int kase=1;
  21. int t;
  22. cin>>t;
  23. while(t--)
  24. {
  25. deque<int>q;
  26. int a;
  27. string str,btr,temp;
  28.  
  29. cin>>str>>btr;
  30. int s,b,i,j,sum=0,c=0,mod;
  31.  
  32. if(btr.size()<str.size())swap(str,btr);
  33. s=str.size();
  34. b=btr.size();
  35.  
  36. // cout<<" "<<str<<" "<<btr<<" ";
  37. j=s-1;
  38. for(i=b-1;i>=0;i--)
  39. {
  40. if(j>=0)
  41. {
  42. a=btr[i]-48+str[j]-48;
  43. sum=a+c;
  44. // cout<<"\n"<<sum<<" ";
  45.  
  46. if(sum>9)c=1;
  47. else c=0;
  48. mod=sum%10;
  49. // cout<<mod;
  50. q.push_front(mod);
  51.  
  52. j--;
  53. }
  54. else
  55. {
  56. a=btr[i]-48+c;
  57. mod=a%10;
  58. q.push_front(mod);
  59. if(a>9)c=1;
  60. else c=0;
  61. }
  62.  
  63. }
  64.  
  65.  
  66. if(c==1)q.push_front(1);
  67.  
  68.  
  69. cout<<"Case #"<<kase++<<": ";
  70.  
  71. for(auto x:q)
  72. {
  73. cout<<x;
  74. }
  75.  
  76. cout<<"\n";
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement