Advertisement
pavlinpetkov88

Untitled

Jan 29th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class FoldAndSum
  5. {
  6. public static void Main()
  7. {
  8.  
  9. //int[] array = Console.ReadLine().Split(' ')
  10. // .Select(int.Parse)
  11. // .ToArray();
  12.  
  13. //int[] firstPart = new int[array.Length / 4];
  14. //int[] secondPart = new int[array.Length / 4];
  15. //int[] thirdPart = new int[array.Length / 4];
  16. //int[] forthPart = new int[array.Length / 4];
  17.  
  18. //int position = 0;
  19. //int part = array.Length / 4;
  20.  
  21. //for (int i = position, j = 0; position < part; position++, j++)
  22. //{
  23. // firstPart[j] = array[position];
  24. //}
  25. //for (int i = position, j = 0; position < (part * 2); position++, j++)
  26. //{
  27. // secondPart[j] = array[position];
  28. //}
  29. //for (int i = position, j = 0; position < (part * 3); position++, j++)
  30. //{
  31. // thirdPart[j] = array[position];
  32. //}
  33. //for (int i = position, j = 0; position < (part * 4); position++, j++)
  34. //{
  35. // forthPart[j] = array[position];
  36. //}
  37.  
  38. //Array.Reverse(firstPart);
  39. //Array.Reverse(forthPart);
  40.  
  41. //int[] firstHaft = new int[array.Length / 2];
  42. //int[] secondHaft = new int[firstHaft.Length];
  43.  
  44. //for (int i = 0, j = firstPart.Length; i < firstPart.Length; i++, j++)
  45. //{
  46. // firstHaft[i] = firstPart[i];
  47. // firstHaft[j] = forthPart[i];
  48. // secondHaft[i] = secondPart[i];
  49. // secondHaft[j] = thirdPart[i];
  50. //}
  51.  
  52. //int[] sumResul = new int[firstHaft.Length];
  53.  
  54. //for (int i = 0; i < firstHaft.Length; i++)
  55. //{
  56. // sumResul[i] += firstHaft[i] + secondHaft[i];
  57. //}
  58.  
  59. //foreach (int result in sumResul)
  60. //{
  61. // Console.Write(result + " ");
  62. //}
  63.  
  64. int[] numbers = Console.ReadLine().Split(' ')
  65. .Select(int.Parse)
  66. .ToArray();
  67.  
  68. int[] leftHaft = new int[numbers.Length / 2];
  69. int[] rightHaft = new int[numbers.Length / 2];
  70.  
  71. for (int i = leftHaft.Length - 1, j = numbers.Length -1, k = 0; i >= 0; i--, j--, k++)
  72. {
  73. leftHaft[k] = numbers[i];
  74. rightHaft[k] = numbers[j];
  75. }
  76.  
  77. int[] revLeftHaft = new int[leftHaft.Length / 2];
  78. int[] revRightHaft = new int[leftHaft.Length / 2];
  79.  
  80. for (int i = 0 , k = revLeftHaft.Length; i < revLeftHaft.Length; i++, k++)
  81. {
  82. revLeftHaft[i] = leftHaft[k];
  83. revRightHaft[i] = rightHaft[i];
  84. }
  85.  
  86. int[] sumLeft = new int[leftHaft.Length];
  87. int[] sumRight = new int[rightHaft.Length];
  88.  
  89. for (int i = 0, j = rightHaft.Length, k = revLeftHaft.Length; i < revRightHaft.Length; i++, k++, j++)
  90. {
  91. sumLeft[i] = revLeftHaft[i];
  92. sumLeft[k] = revRightHaft[i];
  93. sumRight[i] = numbers[k];
  94. sumRight[k] = numbers[j];
  95. }
  96.  
  97. int[] result = new int[numbers.Length / 2];
  98.  
  99. for (int i = 0; i < rightHaft.Length; i++)
  100. {
  101. result[i] += sumLeft[i] + sumRight[i];
  102. }
  103.  
  104.  
  105. foreach (var item in result)
  106. {
  107. Console.Write(item + " ");
  108. }
  109.  
  110. Console.WriteLine();
  111.  
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement