Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int input ();
  6. int difference (int, int);
  7. int calculateWrongAns (int);
  8.  
  9. int main()
  10. {
  11. int num1;
  12. int num2;
  13. num1 = input();
  14. num2 = input();
  15.  
  16. int actualAns = difference(num1, num2);
  17. int res = calculateWrongAns(actualAns);
  18. cout << res;
  19. return 0;
  20. }
  21.  
  22. int input () {
  23. int x;
  24. cin >> x;
  25. return x;
  26. }
  27.  
  28. int difference (int x, int y) {
  29. if (x > y) {
  30. return x - y;
  31. } else if (x < y) {
  32. return y - x;
  33. } else {
  34. return 0;
  35. }
  36. }
  37.  
  38. int calculateWrongAns (int actualAns) {
  39. int lastNumber = actualAns % 10;
  40. int otherNumbers = actualAns / 10;
  41. int res;
  42. if (otherNumbers != 0) {
  43. res = (otherNumbers * 10) + (lastNumber == 1 ? 2 : lastNumber - 1);
  44. } else {
  45. res = lastNumber == 1 ? 2 : lastNumber - 1;
  46. }
  47.  
  48. return res;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement