Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 03. Zig-Zag Arrays
- Write a program which creates 2 arrays. You will be given an integer n. On the next n lines you get 2 integers. Form 2 arrays as shown below.
- Examples
- Input Output
- 4 1 10 31 20
- 1 5 5 9 81 41
- 9 10
- 31 81
- 41 20
- 2 80 19
- 80 23 23 31
- 31 19
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03Zig_ZagArrays
- {
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- string[] arrayOne = new string[number];
- string[] arrayTwo = new string[number];
- for (int i = 0; i < number; i++)
- {
- string[] current = Console.ReadLine().Split();
- if (i % 2 == 0)
- {
- arrayOne[i] = current[0];
- arrayTwo[i] = current[1];
- }
- else
- {
- arrayOne[i] = current[1];
- arrayTwo[i] = current[0];
- }
- }
- Console.WriteLine(string.Join(" ", arrayOne));
- Console.WriteLine(string.Join(" ", arrayTwo));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment