Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stack>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <math.h>
  6. using namespace std;
  7. int main()
  8. {
  9.  
  10. int think1=0;
  11. int think2=0;
  12. int a;
  13. int b;
  14.  
  15.  
  16. stack<int> keep;
  17. string in1;
  18. cin>>in1;
  19. a=in1.length();
  20.  
  21. stack<int> keep2;
  22. string in2;
  23. cin>>in2;
  24. b=in2.length();
  25.  
  26. stack<int> show;
  27.  
  28.  
  29. int run1=0;
  30. while(in1[run1]!=NULL)
  31. {
  32. keep.push(in1[run1]-48);
  33. run1=run1+1;
  34. }
  35.  
  36. int run2=0;
  37. while(in2[run2]!=NULL)
  38. {
  39. keep2.push(in2[run2]-48);
  40. run2=run2+1;
  41. }
  42. while(true)
  43. {
  44.  
  45. if(!keep.empty())
  46. {
  47. think1=keep.top();
  48. keep.pop();
  49. }
  50. if(!keep2.empty())
  51. {
  52. think2=keep2.top();
  53. keep.pop();
  54. }
  55. if(think1+think2>=10)
  56. {
  57. if(keep.empty())
  58. {
  59. show.push(think1+think2);
  60. break;
  61. }
  62. else if(a>b)
  63. {
  64. show.push((think1+think2)%10);
  65. int use=keep.top()+1;
  66. keep.pop();
  67. keep.push(use);
  68. }
  69. else
  70. {
  71. show.push((think1+think2)%10);
  72. int use=keep2.top()+1;
  73. keep2.pop();
  74. keep2.push(use);
  75. }
  76. }
  77. else if(think1+think2<10)
  78. {
  79. show.push(think1+think2);
  80. }
  81. }
  82. cout<<"as";
  83. while(!show.empty())
  84. {
  85. cout<<show.top();
  86. show.pop();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement