Advertisement
Guest User

Zig-Zag Arrays

a guest
Oct 12th, 2018
1,637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.     public class Program
  5.     {
  6.         public static void Main()
  7.         {
  8.             int n = int.Parse(Console.ReadLine());
  9.  
  10.             int[] firstArray = new int[n];
  11.             int[] secondArray = new int[n];
  12.  
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  16.                 for (int j = 0; j < input.Length - 1; j++)
  17.                 {
  18.                     secondArray[i] = input[j]; //*
  19.                     firstArray[i] = input[j + 1]; //*
  20.                 }
  21.             }
  22.  
  23.             for (int i = 0; i < n; i+= 2) //*
  24.             {
  25.                 int temp = 0; //*
  26.                 temp = secondArray[i];
  27.                 secondArray[i] = firstArray[i];
  28.                 firstArray[i] = temp;
  29.             }
  30.  
  31.             string firstOutput = string.Join(" ", firstArray);
  32.             string secondOutput = string.Join(" ", secondArray);
  33.  
  34.             Console.WriteLine(firstOutput);
  35.             Console.WriteLine(secondOutput);
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement