JulianJulianov

CondenseArrayToNumber

Feb 5th, 2020
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _8CondenseArrayToNumber
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {/*
  10. int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11. int[] newArray = new int[array.Length - 1];
  12.  
  13. if (array.Length == 1)
  14. {
  15. Console.WriteLine(array[0]);
  16. return;
  17. }
  18.  
  19. for (int i = 0; i < array.Length; i++)
  20. {
  21. for (int d = 0; d < newArray.Length - i; d++)
  22. {
  23. newArray[d] = array[d] + array[d + 1];
  24. }
  25. array = newArray;
  26. }
  27. Console.WriteLine(newArray[0]);*/
  28. string input = Console.ReadLine();
  29. string[] numbers = input.Split(' ');
  30. int[] array = new int[numbers.Length];
  31.  
  32. for (int i = 0; i < array.Length; i++)
  33. {
  34. array[i] = int.Parse(numbers[i]);
  35. }
  36.  
  37. int[] condensed = new int[array.Length - 1];
  38.  
  39. while (array.Length > 1)
  40. {
  41. for (int i = 0; i < array.Length - 1; i++)
  42. {
  43. condensed[i] = array[i] + array[i + 1];
  44. array[i] = condensed[i];
  45. }
  46. Array.Resize(ref condensed, condensed.Length - 1);
  47. Array.Resize(ref array, array.Length - 1);
  48. }
  49.  
  50. foreach (var element in array)
  51. {
  52. Console.WriteLine(element);
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment