Advertisement
Guest User

dsf

a guest
May 27th, 2015
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1.    
  2.  
  3.     using System;
  4.     using System.Linq;
  5.      
  6.     class HalfSum
  7.     {
  8.         static void Main()
  9.         {
  10.             long n = long.Parse(Console.ReadLine());
  11.      
  12.             //declare an array storing all entered values
  13.             long[] enteredValues = new long[2*n];
  14.             //fill in the array propting the user for values
  15.             for (long i = 0; i < 2*n; i++)
  16.             {
  17.                 enteredValues[i] = long.Parse(Console.ReadLine());
  18.             }
  19.            
  20.             //declare 2 new arrays. One for the first half of of the enteredValues array and another for the second half
  21.             long[] leftSide = enteredValues.Take(enteredValues.Length / 2).ToArray();
  22.             long[] rightSide = enteredValues.Skip(enteredValues.Length / 2).ToArray();
  23.      
  24.             long leftSideSum = leftSide.Sum();
  25.             long rightSideSum = rightSide.Sum();
  26.      
  27.             if (leftSideSum == rightSideSum)
  28.             {
  29.                 Console.WriteLine("Yes, sum=" + leftSideSum);
  30.             }
  31.      
  32.             else if (leftSideSum > rightSideSum)
  33.             {
  34.                 Console.WriteLine("No, diff=" + (leftSideSum-rightSideSum));
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("No, diff=" + (rightSideSum-leftSideSum));
  39.             }
  40.            
  41.                
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement