VelizarAvramov

11. Equal Sums

Dec 2nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _11._Equal_Sums_Veronika
  5. {
  6.     class EqualSumVer
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] input = Console.ReadLine().
  11.                 Split(' ').Select(int.Parse).ToArray();
  12.  
  13.             if (input.Length == 1)
  14.             {
  15.                 Console.WriteLine(0);
  16.                 return;
  17.             }
  18.  
  19.  
  20.             int result = 0;
  21.             bool isValid = false;
  22.             for (int i = 0; i < input.Length; i++)
  23.             {
  24.                 int leftSum = 0;
  25.                 int rigthSum = 0;
  26.  
  27.                 for (int j = 0; j < i; j++)
  28.                 {
  29.                     leftSum += input[j];
  30.                 }
  31.  
  32.                 for (int j = i + 1; j < input.Length; j++)
  33.                 {
  34.                     rigthSum += input[j];
  35.                 }
  36.                 if (leftSum == rigthSum)
  37.                 {
  38.                     isValid = true;
  39.                     Console.WriteLine(i);
  40.                     break;
  41.                 }              
  42.             }
  43.             if (isValid == false)
  44.             {
  45.                 Console.WriteLine("no");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment