Advertisement
fbinnzhivko

Untitled

May 26th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.  
  8.         int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  9.         int maxNumber = numbers.Max(); //Gets the max number of the array
  10.         int totalSumOfNumber = numbers.Sum(); //Gets the total sum of the numbers in the array
  11.         int check = (totalSumOfNumber - maxNumber) / 2; //Gets the sum of the numbers int the array without the max number
  12.  
  13.         if (check == maxNumber) //Checks if the sum is equal to the max number
  14.         {
  15.             int index1 = Array.IndexOf(numbers, numbers.Max());
  16.             Console.WriteLine("{0}", index1);
  17.         }
  18.         else
  19.         {
  20.  
  21.             if (numbers.Length == 1)
  22.             {
  23.                 Console.WriteLine(0);
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("no");
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement