Advertisement
VladoG

[Programming Fundamentals] (Arrays)- 11. Equal Sums

Jun 7th, 2016
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 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 _11.Equal_Sums
  8.     {
  9.     class EqualSums
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             int size = nums.Length;
  15.             int sumLeft = 0;
  16.             int sumRight = 0;
  17.             int countPos = 0;
  18.  
  19.             if (size == 1)
  20.                 {
  21.                 Console.WriteLine(size - 1);
  22.                 }
  23.             else
  24.                 {
  25.                 for (int i = 0; i < size-1; i++)
  26.                     {
  27.                     sumLeft += nums[i];
  28.                     countPos++;
  29.                     sumRight = 0;
  30.                     for (int j = size-1; j > i; j--)
  31.                         {
  32.                         sumRight += nums[j];
  33.                         if (sumRight==sumLeft && (j-i)>1)
  34.                             {
  35.                             size = 0;
  36.                             break;
  37.                             }
  38.                         } // end-J
  39.                     if (size==0)
  40.                         {
  41.                         break;
  42.                         }
  43.                     } // end-I
  44.                 if (size==0)
  45.                     {
  46.                     Console.WriteLine(countPos);
  47.                     }
  48.                 else
  49.                     {
  50.                     Console.WriteLine("no");
  51.                     }
  52.  
  53.                 }
  54.  
  55.             } // End of Main
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement