Advertisement
vaakata

EqualSumsSingleForLoop_31.05.2016

May 31st, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 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 EqualSumsShort_31._05._2016
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  14.  
  15.             int[,] result = new int[2, input.Length];
  16.             result[0, 0] = 0;
  17.             result[1, 0] = input.Sum() - input[0];
  18.  
  19.             if (input.Length == 1)
  20.             {
  21.                 Console.WriteLine(0);
  22.             }
  23.             else
  24.             {
  25.                 for (int i = 0; i < input.Length; i++)
  26.                 {
  27.                     result[0, Math.Max(i, 1)] = result[0, Math.Max(i - 1, 0)] + input[(int)Math.Max(i - 1, 0)];    
  28.                     result[1, Math.Max(i, 1)] = result[1, Math.Max(i - 1, 0)] - input[Math.Max(i, 1)];
  29.  
  30.                     if (result[0, i] == result[1, i])
  31.                     {
  32.                         Console.WriteLine(i);
  33.                         return;
  34.                     }
  35.                 }
  36.                 Console.WriteLine("no");
  37.             }            
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement