Militsa

06. Fold and Sum

Dec 7th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Fold_and_Sum
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] myInts = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
  15.  
  16.             int half = myInts.Length / 2;
  17.             int part = half / 2;
  18.  
  19.             int[] sum = new int[half];
  20.  
  21.             for (int p = 0; p <= 1; p++) {
  22.                 for (int i = 0; i < part; i++) {
  23.                     int firstIndex = ((part - 1) + (-i)) + (p * (half + part));
  24.                     int secondIndex = part + i + (p * part);
  25.                     sum[i + (p * part)] = myInts[firstIndex] + myInts[secondIndex];
  26.                 }
  27.             }
  28.  
  29.             Console.WriteLine(string.Join(" ", sum));
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment