Advertisement
Guest User

Zig-Zag Arrays

a guest
Oct 17th, 2020
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ZigZagArrays
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var linesCount = int.Parse(Console.ReadLine());
  11.  
  12.             var firstArray = new int[linesCount];
  13.             var secondArray = new int[linesCount];
  14.  
  15.             for (var index = 0; index < linesCount; index++)
  16.             {
  17.                 var input = Console.ReadLine()
  18.                     .Split(' ')
  19.                     .Select(int.Parse)
  20.                     .ToArray();
  21.  
  22.                 if (index % 2 == 0)
  23.                 {
  24.                     firstArray[index] = input[0];
  25.                     secondArray[index] = input[1];
  26.                 }
  27.                 else
  28.                 {
  29.                     firstArray[index] = input[1];
  30.                     secondArray[index] = input[0];
  31.                 }
  32.             }
  33.  
  34.             var firstArrayOutput = string.Join(' ', firstArray);
  35.             var secondArrayOutput = string.Join(' ', secondArray);
  36.             var finalOutput = string.Join(Environment.NewLine, firstArrayOutput, secondArrayOutput);
  37.  
  38.             Console.WriteLine(finalOutput);
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement