Advertisement
bacco

Equal Sums

Jun 2nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace EqualSums
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] arr = Console.ReadLine()
  12.                                .Split(' ')
  13.                                .Select(int.Parse)
  14.                                .ToArray();
  15.             int leftSum  = 0;
  16.             int rightSum = 0;
  17.             bool isEqual = false;
  18.  
  19.             for (int i = 0; i < arr.Length ; i++)
  20.             {
  21.                 for (int left = 0; left < i; left++)
  22.                 {
  23.                     leftSum += arr[left];
  24.                 }
  25.                 for (int right = i + 1; right < arr.Length; right++)
  26.                 {
  27.                     rightSum += arr[right];
  28.                 }
  29.                 if (leftSum == rightSum)
  30.                 {
  31.                     Console.WriteLine(i);
  32.                     isEqual = true;
  33.                     break;
  34.                 }
  35.                 leftSum  = 0;
  36.                 rightSum = 0;
  37.             }
  38.             if (!isEqual)
  39.             {
  40.                 Console.WriteLine("no");
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement