Advertisement
bullit3189

Fold and Sum - Arrays

Jan 29th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.  
  12. int fourK = nums.Length;
  13.  
  14. int firstK = fourK/4;
  15. int midK = fourK/2;
  16. int lastK = fourK/4;
  17.  
  18. List<int> firstKs = new List<int>();
  19.  
  20. for (int i=0; i<firstK; i++)
  21. {
  22. firstKs.Add(nums[i]);
  23. }
  24.  
  25. firstKs.Reverse();
  26.  
  27. List<int> midKs = new List<int>();
  28.  
  29. for (int i=firstK; i<firstK+midK; i++)
  30. {
  31. midKs.Add(nums[i]);
  32. }
  33.  
  34. List<int> lastKs = new List<int>();
  35.  
  36. for (int i= nums.Length-1; i>=midK + lastK; i--)
  37. {
  38. lastKs.Add(nums[i]);
  39. }
  40.  
  41. firstKs.AddRange(lastKs);
  42.  
  43. List<int>result = new List<int>();
  44.  
  45. for (int i=0; i<midKs.Count; i++)
  46. {
  47. int num = firstKs[i] + midKs[i];
  48. result.Add(num);
  49. }
  50. Console.WriteLine(string.Join(" ",result));
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement