Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Fold_and_Sum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. int k = arr.Length / 4;
  15. int[] midArr = new int[2 * k];
  16. int[] upperArr1 = new int[k];
  17. int[] upperArr2 = new int[k];
  18. int[] sumArr = new int[2 * k];
  19.  
  20. // defining the lower row
  21. for (int i = 0; i < 2 * k; i++)
  22. {
  23. midArr[i] = arr[i + k];
  24. }
  25. //defining the upper row
  26. //first half
  27. for (int i = 0; i < k; i++)
  28. {
  29. upperArr1[i] = arr[i];
  30. }
  31. upperArr1 = upperArr1.Reverse().ToArray();
  32.  
  33. // second half
  34. for (int i = 0; i < k; i++)
  35. {
  36. upperArr2[i] = arr[3 * k + i];
  37. }
  38. upperArr2 = upperArr2.Reverse().ToArray();
  39.  
  40. // combining the first and the second half
  41. int[] combined = upperArr1.Concat(upperArr2).ToArray();
  42.  
  43. // getting the sum of the arrays
  44. for (int i = 0; i < 2*k; i++)
  45. {
  46. sumArr[i] = combined[i] + midArr[i];
  47. }
  48. for (int i = 0; i < 2 * k; i++)
  49. {
  50. Console.Write(sumArr[i] + " ");
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement