simonradev

HalfSumElements

Feb 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LiveDemoII
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main()
  8.         {
  9.             int numberOfInputs = int.Parse(Console.ReadLine());
  10.  
  11.             int maxNumber = int.MinValue;
  12.             int sum = 0;
  13.             bool thereIsMaxNumber = false;
  14.             for (int currInput = 0; currInput < numberOfInputs; currInput++)
  15.             {
  16.                 int number = int.Parse(Console.ReadLine());
  17.  
  18.                 sum += number;
  19.  
  20.                 if (maxNumber < number)
  21.                 {
  22.                     maxNumber = number;
  23.  
  24.                     thereIsMaxNumber = true;
  25.                 }
  26.             }
  27.  
  28.             sum -= maxNumber;
  29.             bool theSumIsEqual = maxNumber == sum;
  30.  
  31.             string result = string.Empty;
  32.             if (thereIsMaxNumber && theSumIsEqual)
  33.             {
  34.                 result = $"Yes\r\nSum = {maxNumber}";
  35.             }
  36.             else
  37.             {
  38.                 result = $"No\r\nDiff = {Math.Abs(maxNumber - sum)}";
  39.             }
  40.  
  41.             Console.WriteLine(result);
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment