Advertisement
Guest User

11. Equal Sums

a guest
Oct 6th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class InstructionSet_broken
  5. {
  6. static void Main()
  7. {
  8.  
  9. int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  10.  
  11. int arrsum = 0;
  12. bool isFound = false;
  13. if (arr.Length == 1)
  14. {
  15. Console.WriteLine("0");
  16. }
  17. else
  18. {
  19. for (int i = 0; i < arr.Length; i++)
  20. {
  21. arrsum += arr[i];
  22. int sum = 0;
  23. if (i == arr.Length-1 )
  24. {
  25. break;
  26. }
  27. for (int j = arr.Length - 1; j >= 0; j--)
  28. {
  29. sum += arr[j];
  30. if (arrsum == sum)
  31. {
  32. Console.WriteLine(i + 1);
  33. isFound = true;
  34. break;
  35. }
  36. else if (arrsum < sum)
  37. {
  38. break;
  39. }
  40. if (isFound)
  41. {
  42. break;
  43. }
  44. }
  45. }
  46. if (!isFound)
  47. {
  48. Console.WriteLine("no");
  49. }
  50. }
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement