Advertisement
vardanss

Zig-Zag Arrays

Jun 10th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _03_ZigZagArrays
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             string firstRow = "";
  12.             string secondRow = "";
  13.             string firstRowOutput = "";
  14.             string secondRowOutput = "";
  15.             for (int i = 1; i <= n; i++)
  16.             {
  17.                 string[] array = Console.ReadLine().Split().ToArray();
  18.                 if (i % 2 != 0)
  19.                 {
  20.                     firstRow = array[0];
  21.                     secondRow = array[1];
  22.                 }
  23.                 else if(i % 2 == 0)
  24.                 {
  25.                     firstRow = array[1];
  26.                     secondRow = array[0];
  27.                 }
  28.                 firstRowOutput += firstRow + " ";
  29.                 secondRowOutput += secondRow + " ";
  30.             }
  31.             Console.WriteLine(firstRowOutput);
  32.             Console.WriteLine(secondRowOutput);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement