Advertisement
braveheart1989

EqualSums

Jun 7th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 _12.EqualSums
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //
  14.             int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  15.            // int[] nums = new int[] {1, 2, 3, 3};
  16.             bool areEqual = false;
  17.             for (int current = 0; current < nums.Length; current++)
  18.             {
  19.                 int sumLeft = 0;
  20.                 int sumRight = 0;
  21.  
  22.                 for (int curr = 0; curr < current+1; curr++)
  23.                 {
  24.                     sumLeft += nums[curr];
  25.                 }
  26.                 for (int i = nums.Length - 1; i >= current; i--)
  27.                 {
  28.                     sumRight += nums[i];
  29.                 }
  30.                
  31.                 if (sumLeft==sumRight)
  32.                 {
  33.                     Console.WriteLine(current);
  34.                     areEqual = true;
  35.                 }
  36.             }
  37.             if (!areEqual)
  38.             {
  39.                 Console.WriteLine("no");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement