Advertisement
Spiderbait90

Untitled

Apr 11th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _11.Equal_Sums
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var numbers = Console.ReadLine()
  14.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.             int leftSum = 0;
  18.             int rightSum = 0;
  19.             for (int left = 0; left < numbers.Length-2 ; left++)
  20.             {                
  21.                     leftSum += numbers[left];
  22.                 for (int right = left + 2; right < numbers.Length; right++)
  23.                 {
  24.                     if (left == 0)
  25.                         rightSum += numbers[right];
  26.                     else
  27.                     {
  28.                         rightSum -= numbers[left + 1];
  29.                         break;
  30.                     }
  31.                 }
  32.                 if (leftSum == rightSum)
  33.                 {
  34.                     Console.WriteLine(left + 1);
  35.                     return;
  36.                 }
  37.             }
  38.             if(numbers.Length==1)
  39.             {
  40.                 Console.WriteLine(0);
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine("no");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement