Posted By

ELCesarMaat on 04/14/18


Tagged


Versions (?)

Contador de "llevar mas uno" en una suma (incompleto))


 / Published in: C++
 

Text

  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4. int main()
  5. {
  6. string x, y;
  7. cin>>x;
  8. cin>>y;
  9. int num1[x.length()-1];
  10. int num2[y.length()-1];
  11.  
  12. for(int i=0; i<=x.length()-1; i++)
  13. {
  14. if(x[i]=='1')
  15. {
  16. num1[i]=1;
  17. }
  18.  
  19. if(x[i]=='2')
  20. {
  21. num1[i]=2;
  22. }
  23.  
  24. if(x[i]=='3')
  25. {
  26. num1[i]=3;
  27. }
  28.  
  29. if(x[i]=='4')
  30. {
  31. num1[i]=4;
  32. }
  33.  
  34. if(x[i]=='5')
  35. {
  36. num1[i]=5;
  37. }
  38.  
  39. if(x[i]=='6')
  40. {
  41. num1[i]=6;
  42. }
  43.  
  44. if(x[i]=='7')
  45. {
  46. num1[i]=7;
  47. }
  48. if(x[i]=='8')
  49. {
  50. num1[i]=8;
  51. }
  52. if(x[i]=='9')
  53. {
  54. num1[i]=9;
  55. }
  56. if(x[i]=='0')
  57. {
  58. num1[i]=0;
  59. }
  60.  
  61. }
  62. for(int i=0; i<=y.length()-1; i++)
  63. {
  64. if(y[i]=='1')
  65. {
  66. num2[i]=1;
  67. }
  68.  
  69. if(y[i]=='2')
  70. {
  71. num2[i]=2;
  72. }
  73.  
  74. if(y[i]=='3')
  75. {
  76. num2[i]=3;
  77. }
  78.  
  79. if(y[i]=='4')
  80. {
  81. num2[i]=4;
  82. }
  83.  
  84. if(y[i]=='5')
  85. {
  86. num2[i]=5;
  87. }
  88.  
  89. if(y[i]=='6')
  90. {
  91. num2[i]=6;
  92. }
  93.  
  94. if(y[i]=='7')
  95. {
  96. num2[i]=7;
  97. }
  98. if(y[i]=='8')
  99. {
  100. num2[i]=8;
  101. }
  102. if(y[i]=='9')
  103. {
  104. num2[i]=9;
  105. }
  106. if(y[i]=='0')
  107. {
  108. num2[i]=0;
  109. }
  110.  
  111. }
  112. int max;
  113. if(x.length()>y.length())
  114. {
  115. max=x.length();
  116. }
  117. else if(x.length()<y.length())
  118. {
  119. max=y.length();
  120. }
  121. else if(x.length()==y.length())
  122. {
  123. max=y.length();
  124. }
  125. int cont=0;
  126. for(int i=0; i<=max-1; i++)
  127. {
  128. if((num1[i]+num2[i])>9)
  129. {
  130. cont=cont+1;
  131. }
  132. }
  133. cout<<"\n\n"<<cont;
  134.  
  135. }

Report this snippet  

You need to login to post a comment.