zh_stoqnov

Sum of Elements

Oct 25th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. class SumOfElements
  4. {
  5. static void Main(string[] args)
  6. {
  7. string inputLine = Console.ReadLine();
  8. string[] numbers = inputLine.Split(' ');
  9.  
  10. long max = long.MinValue;
  11. long sum = 0;
  12. for (int i = 0; i < numbers.Length; i++)
  13. {
  14. int element = int.Parse(numbers[i]);
  15. sum = sum + element;
  16. if (element > max)
  17. {
  18. max = element;
  19. }
  20. }
  21.  
  22. if (sum == (2 * max))
  23. {
  24. Console.WriteLine("Yes, sum=" + max);
  25. }
  26. else
  27. {
  28. long diff = Math.Abs(sum - (2 * max));
  29. Console.WriteLine("No, diff=" + diff);
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment