Mim1111

Untitled

Jan 30th, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ЕА06._Equal_Sum
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] arr = Console.ReadLine()
  11. .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  12. .Select(int.Parse)
  13. .ToArray();
  14.  
  15. bool index = false;
  16. int position = 0;
  17.  
  18. for (int i = 0; i < arr.Length; i++)
  19. {
  20. int sumLeft = 0;
  21. int sumRight = 0;
  22.  
  23.  
  24. for (int j = 0; j < i; j++) //left
  25. {
  26. sumLeft += arr[j];
  27. }
  28.  
  29. for (int k = i+1; k < arr.Length; k++) //right
  30. {
  31. sumRight += arr[k];
  32. }
  33.  
  34. if (sumRight==sumLeft)
  35. {
  36. index=true;
  37. position = i;
  38. }
  39.  
  40. }
  41.  
  42. if (index==true)
  43. {
  44. Console.WriteLine(position);
  45. }
  46. else
  47. {
  48. Console.WriteLine("no");
  49. }
  50. }
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment