petyaminkova91

Untitled

Oct 11th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _8._CondenseArrayТoNumber
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] nums = Console.ReadLine()
  11. .Split()
  12. .Select(int.Parse)
  13. .ToArray();
  14.  
  15.  
  16. int result = 0;
  17.  
  18. while (nums.Length > 1)
  19. {
  20.  
  21. int[] condensed = new int[nums.Length - 1];
  22.  
  23. for (int i = 0; i < condensed.Length; i++)
  24. {
  25. condensed[i] = nums[i] + nums[i + 1];
  26. }
  27.  
  28. nums = condensed;
  29. result = condensed[0];
  30.  
  31. }
  32. if (nums.Length == 1)
  33. {
  34. result = nums[0];
  35. }
  36. Console.WriteLine(result);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment