Advertisement
vaakata

EqualSumsStadard_30.05.2016

May 30th, 2016
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 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 EqualSums_27._05._2016
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] number = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int sumLeft = 0;
  15.             int sumRight = 0;
  16.  
  17.             for (int i = 0; i <= number.Length - 1; i++)
  18.             {
  19.                 if (number.Length == 1)
  20.                 {
  21.                     Console.WriteLine(0);
  22.                     return;
  23.                 }
  24.                 sumLeft = 0;
  25.                 for (int iLeft = i; iLeft > 0; iLeft--)
  26.                 {
  27.                     int nextPosition = iLeft - 1;
  28.                     if (iLeft > 0)
  29.                     {
  30.                         sumLeft += number[nextPosition];
  31.                     }
  32.                 }              
  33.  
  34.                 sumRight = 0;              
  35.                 for (int iRight = i; iRight < number.Length; iRight++)
  36.                 {
  37.                     int nextPosition = (iRight + 1);
  38.                     if (iRight < number.Length - 1)
  39.                     {
  40.                         sumRight += number[nextPosition];
  41.                     }
  42.                 }
  43.  
  44.                 if (sumLeft == sumRight)
  45.                 {
  46.                     Console.WriteLine(i);
  47.                     return;
  48.                 }
  49.                
  50.             }
  51.             Console.WriteLine("no");
  52.         }
  53.     }        
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement