Advertisement
vaakata

EqualSums_Ver.2.0_27.05.2016

May 27th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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.             int index = 0;
  17.  
  18.             for (int i = 1; i < number.Length - 1; i++)
  19.             {
  20.                 sumLeft = 0;
  21.                 for (int iLeft = 0; iLeft < i; iLeft++)
  22.                 {
  23.                     sumLeft += number[iLeft];
  24.                 }
  25.  
  26.                 if (sumLeft == number[i])
  27.                 {
  28.                     sumRight = 0;
  29.                     for (int iRight = i + 1; iRight < number.Length; iRight++)
  30.                     {
  31.                         sumRight += number[iRight];
  32.                     }
  33.                 }
  34.                 if (sumLeft == sumRight)
  35.                 {
  36.                     index = i;
  37.                     break;
  38.                 }
  39.  
  40.             }
  41.             Print(number, index);
  42.         }
  43.  
  44.         static void Print(int[] inputNumbers, int index)
  45.         {
  46.             if (index != 0)
  47.             {
  48.                 Console.WriteLine(index);
  49.             }
  50.             else if (index == 0 && inputNumbers.Length > 2)
  51.             {
  52.                 Console.WriteLine("no");
  53.             }
  54.  
  55.             if (inputNumbers.Length == 2)
  56.             {
  57.                 Console.WriteLine("no");
  58.             }
  59.  
  60.             if (inputNumbers.Length == 1)
  61.             {
  62.                 Console.WriteLine(0);
  63.             }
  64.         }
  65.     }        
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement