Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Equal_Sums_Left_Right_Position
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int a = int.Parse(Console.ReadLine());
  10. int b = int.Parse(Console.ReadLine());
  11. int sumLeft = 0;
  12. int sumRight = 0;
  13. int sumMiddle = 0;
  14. int sumAdd = 0;
  15. for (int i = a; i <= b; i++)
  16. {
  17. string iToString = i.ToString();
  18. for (int j = 0; j < iToString.Length; j++)
  19. {
  20. char num = iToString[j];
  21. int numInt = int.Parse(num.ToString());
  22. int position = j + 1;
  23. if (position == 1 || position == 2)
  24. {
  25. sumLeft += numInt;
  26. }
  27. if (position == 4 || position == 5)
  28. {
  29. sumRight += numInt;
  30. }
  31. if (position == 3)
  32. {
  33. sumMiddle = numInt;
  34. }
  35. }
  36. if (sumLeft == sumRight)
  37. {
  38. Console.Write(iToString + " ");
  39. }
  40. if (sumLeft > sumRight)
  41. {
  42. sumAdd = sumRight + sumMiddle;
  43. if (sumLeft == sumAdd)
  44. {
  45. Console.Write(iToString + " ");
  46. }
  47. }
  48. else if (sumLeft < sumRight)
  49. {
  50. sumAdd = sumLeft + sumMiddle;
  51. if (sumRight == sumAdd)
  52. {
  53. Console.Write(iToString + " ");
  54. }
  55.  
  56. }
  57. sumLeft = 0;
  58. sumRight = 0;
  59. sumMiddle = 0;
  60. sumAdd = 0;
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement