Advertisement
vaakata

Equal Sums_27.05.2016

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