Advertisement
bacco

Equal Sums (New version)

Jun 2nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace EqualSums
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.           int[] numbers = Console.ReadLine()
  12.                                  .Split(' ')
  13.                                  .Select(int.Parse)
  14.                                  .ToArray();
  15.             int rightSum = 0;
  16.  
  17.             foreach (var number in numbers)
  18.             {
  19.                 rightSum += number;
  20.             }
  21.            
  22.             int  leftSum = 0;
  23.             bool  index  = false;
  24.  
  25.             for (int i = 0; i < numbers.Length ; i++)
  26.             {
  27.                 int curentNum = numbers[i];
  28.                 rightSum -= curentNum;
  29.  
  30.                 if (leftSum == rightSum)
  31.                 {
  32.                     index = true;
  33.                     Console.WriteLine(i);
  34.                     break;
  35.                 }
  36.                 leftSum += curentNum;
  37.             }
  38.             if (!index)
  39.             {
  40.                 Console.WriteLine("no");
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement