Advertisement
Guest User

SumOfElements

a guest
Sep 7th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         int.Parse("5.5");
  10.         List<double> sequence = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToList();
  11.         if (sequence.Count == 0)
  12.         {
  13.             Console.WriteLine("Yes, sum=0");
  14.             return;
  15.         }
  16.         double max = sequence.Max();
  17.         sequence.Remove(max);
  18.  
  19.         if (sequence.Sum() == max)
  20.         {
  21.             Console.WriteLine("Yes, sum=" + max);
  22.         }
  23.         else
  24.         {
  25.             double diff = Math.Abs(max - sequence.Sum());
  26.             Console.WriteLine("No, diff=" + diff);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement