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.88 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. temp1a = 0, temp2a = 0, temp3a = 1, a = 0, b = 0, jakieDzialanie = 0;
  13. cin >> a;
  14. cin >> b;
  15. cin >> jakieDzialanie;
  16.  
  17. switch(jakieDzialanie)
  18. {
  19. case '+':
  20. if (a == b)
  21. {
  22. return 0;
  23. }
  24. if (b > a)
  25. {
  26. temp1 = b - a;
  27. for (int i = 0; i <= temp1; i++)
  28. {
  29. temp1a = temp1a + a;
  30. a = a + 1;
  31. }
  32. }
  33. else if (b < a)
  34. {
  35. temp1 = a - b;
  36. for (int i = 0; i <= temp1; i++)
  37. {
  38. temp1a = temp1a + b;
  39. b = b + 1;
  40. }
  41. }
  42. cout << temp1a << endl;
  43. break;
  44. case '-':
  45. if (a == b)
  46. {
  47. return 0;
  48. }
  49. if (b < a)
  50. {
  51. temp2 = (b - a);
  52. if (temp2 < 0)
  53. {
  54. temp2 = (temp2*(-1));
  55. }
  56. for (int i = 0; i <= temp2; i++)
  57. {
  58. temp2a = temp2a - a;
  59. a = a - 1;
  60. }
  61. }
  62. else if (b > a)
  63. {
  64. temp2 = (a - b);
  65. if (temp2 < 0)
  66. {
  67. temp2 = (temp2*(-1));
  68. }
  69. for (int i = 0; i <= temp2; i++)
  70. {
  71. temp2a = temp2a - b;
  72. b = b - 1;
  73. }
  74. }
  75. cout << temp2a << endl;
  76. break;
  77. case '*':
  78. if (a == b)
  79. {
  80. return 0;
  81. }
  82. if (b > a)
  83. {
  84. temp3 = b - a;
  85. for (int i = 0; i <= temp3; i++)
  86. {
  87. temp3a = temp3a * a;
  88. a = a + 1;
  89. }
  90. }
  91. else if (b < a)
  92. {
  93. temp3 = a - b;
  94. for (int i = 0; i <= temp3; i++)
  95. {
  96. temp3a = temp3a * b;
  97. b = b + 1;
  98. }
  99. }
  100. cout << temp3a << endl;
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement