tanya_zheleva

11

Jan 31st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] numbers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  11.                 .Select(int.Parse)
  12.                 .ToArray();
  13.  
  14.             if (numbers.Length == 0)
  15.             {
  16.                 Console.WriteLine(numbers[0]);
  17.             }
  18.             else
  19.             {
  20.                 bool found = false;
  21.  
  22.                 for (int i = 0; i < numbers.Length; i++)
  23.                 {
  24.                     int rightSum = 0;
  25.                     int leftSum = 0;
  26.  
  27.                     for (int l = 0; l <= i; l++)
  28.                     {
  29.                         leftSum += numbers[l];
  30.                     }
  31.  
  32.                     for (int r = numbers.Length - 1; r >= i; r--)
  33.                     {
  34.                         rightSum += numbers[r];
  35.                     }
  36.  
  37.                     if (leftSum == rightSum)
  38.                     {
  39.                         Console.WriteLine(i);
  40.                         found = true;
  41.                         break;
  42.                     }
  43.                 }
  44.  
  45.                 if (!found)
  46.                 {
  47.                     Console.WriteLine("no");
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment