Advertisement
martyz

Equal sum

Oct 11th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 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 EqualSum
  8. {
  9.     class Program
  10.     {
  11.  
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             long[] input = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
  16.             if (input.Length == 1)
  17.             {
  18.                 Console.WriteLine(0); return;
  19.             }
  20.            
  21.             else
  22.             {
  23.  
  24.                 for (int i = 0; i < input.Length; i++)
  25.                 {
  26.                     long left = (input.Take(i).Sum());
  27.                     long right = (input.Skip(i + 1).Sum());
  28.                     if (left == right)
  29.                     {
  30.                         Console.WriteLine(i); return;
  31.                     }
  32.  
  33.                 }
  34.             }
  35.             Console.WriteLine("no");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement