Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _11.Equal_Sums
- {
- class Program
- {
- private static int pos = 0;
- private static bool isExist = false;
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- int leftSum = SumLeft(arr, i);
- int rightSum = SumRight(arr, i);
- if (leftSum == rightSum)
- {
- Console.WriteLine(i);
- return;
- }
- }
- Console.WriteLine("no");
- }
- private static int SumLeft(int[] arr, int position)
- {
- int leftSum = 0;
- for (int i = position; i > 0; i--)
- {
- int nextPosition = i - 1;
- if (i==0 )
- {
- leftSum += 0;
- break;
- }
- else
- {
- leftSum += arr[nextPosition];
- }
- }
- return leftSum;
- }
- private static int SumRight(int[] arr, int position)
- {
- int rightSum = 0;
- for (int i = position; i < arr.Length; i++)
- {
- int nextPosition = (i +1 )%arr.Length;
- if (arr.Length == 1 || nextPosition == 0)
- {
- rightSum += 0;
- break;
- }
- else
- {
- rightSum += arr[nextPosition];
- }
- }
- return rightSum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement