Advertisement
bacco

11. Equal Sums

May 7th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace test
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main()
  9.         {
  10.  
  11.  
  12.             int[] arr = Console.ReadLine()
  13.                                    .Split(' ')
  14.                                        .Select(int.Parse)
  15.                                            .ToArray();
  16.  
  17.             var number = 0;
  18.             bool suchIndexExists = false;
  19.  
  20.             if (arr.Length == 1)
  21.                 suchIndexExists = true;
  22.            
  23.  
  24.             for (int i = 0; i < arr.Length; i++)
  25.             {
  26.                 var leftSum = 0;
  27.                 var rightSum = 0;
  28.  
  29.                 for (int l = 0; l < i; l++)
  30.                 {
  31.                     leftSum += arr[l];
  32.                 }
  33.  
  34.                 for (int r = i + 1; r < arr.Length; r++)
  35.                 {
  36.                     rightSum += arr[r];
  37.                 }
  38.  
  39.                 if (leftSum == rightSum)
  40.                 {
  41.                     suchIndexExists = true;
  42.                     number = i ;
  43.                 }
  44.             }
  45.  
  46.             if (suchIndexExists)
  47.             {
  48.                 Console.WriteLine(number);
  49.             }
  50.             else
  51.             {
  52.                 Console.WriteLine("no");
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement