Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a, b, n, temp1 = 0, temp1a = 0, temp2 = 0, temp2a = 0, temp2b = 1, temp3 = 1, temp3a = 1;
  8. char jakieDzialanie;
  9. cin >> n;
  10. for(int i = 0; i < n; i++)
  11. {
  12. cin >> a;
  13. cin >> b;
  14. cin >> jakieDzialanie;
  15.  
  16. switch(jakieDzialanie)
  17. {
  18. case '+':
  19. if (a == b)
  20. {
  21. return 0;
  22. }
  23. if (b > a)
  24. {
  25. temp1 = b - a;
  26. for (int i = 0; i <= temp1; i++)
  27. {
  28. temp1a = temp1a + a;
  29. a = a + 1;
  30. }
  31. }
  32. else if (b < a)
  33. {
  34. temp1 = a - b;
  35. for (int i = 0; i <= temp1; i++)
  36. {
  37. temp1a = temp1a + b;
  38. b = b + 1;
  39. }
  40. }
  41. cout << temp1a << endl;
  42. break;
  43. case '-':
  44. if (a == b)
  45. {
  46. return 0;
  47. }
  48. if (b < a)
  49. {
  50. temp2 = (b - a);
  51. if (temp2 < 0)
  52. {
  53. temp2 = (temp2*(-1));
  54. }
  55. for (int i = 0; i <= temp2; i++)
  56. {
  57. temp2a = temp2a - a;
  58. a = a - 1;
  59. }
  60. }
  61. else if (b > a)
  62. {
  63. temp2 = (a - b);
  64. if (temp2 < 0)
  65. {
  66. temp2 = (temp2*(-1));
  67. }
  68. for (int i = 0; i <= temp2; i++)
  69. {
  70. temp2a = temp2a - b;
  71. b = b - 1;
  72. }
  73. }
  74. cout << temp2a << endl;
  75. break;
  76. case '*':
  77. if (a == b)
  78. {
  79. return 0;
  80. }
  81. if (b > a)
  82. {
  83. temp3 = b - a;
  84. for (int i = 0; i <= temp3; i++)
  85. {
  86. temp3a = temp3a * a;
  87. a = a + 1;
  88. }
  89. }
  90. else if (b < a)
  91. {
  92. temp3 = a - b;
  93. for (int i = 0; i <= temp3; i++)
  94. {
  95. temp3a = temp3a * b;
  96. b = b + 1;
  97. }
  98. }
  99. cout << temp3a << endl;
  100. break;
  101. }
  102. }
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement