Advertisement
Guest User

Untitled

a guest
Sep 11th, 2016
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. int[] numArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  9.  
  10. if (numArray.Length == 1)
  11. {
  12. Console.WriteLine("0"); return;
  13. }
  14.  
  15. int leftSum = 0;
  16. int rightSum = 0;
  17. bool found = false;
  18.  
  19. for (int pos = 0; pos < numArray.Length; pos++) //start searching
  20. {
  21. //sum LEFT numbers from current possition:
  22. for (int L = 0; L < pos; L++)
  23. {
  24. leftSum += numArray[L];
  25. }
  26. //sum RIGHT numbers from current possition:
  27. for (int R = pos+1; R < numArray.Length; R++)
  28. {
  29. rightSum += numArray[R];
  30. }
  31.  
  32. //check if sums are EQUAL:
  33. if (leftSum == rightSum)
  34. {
  35. Console.WriteLine(pos);
  36. found = true;
  37. }
  38. else //if not => reset sums:
  39. {
  40. leftSum = 0;
  41. rightSum = 0;
  42. }
  43. }
  44.  
  45. if (found == false)
  46. {
  47. Console.WriteLine("no");
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement