JulianJulianov

03. Zig-Zag Arrays

Feb 5th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. 03. Zig-Zag Arrays
  2. 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.
  3. Examples
  4. Input Output
  5. 4 1 10 31 20
  6. 1 5 5 9 81 41
  7. 9 10
  8. 31 81
  9. 41 20
  10.  
  11. 2 80 19
  12. 80 23 23 31
  13. 31 19
  14.  
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20.  
  21. namespace _03Zig_ZagArrays
  22. {
  23. class Program
  24. {
  25. static void Main(string[] args)
  26. {
  27. int number = int.Parse(Console.ReadLine());
  28.  
  29. string[] arrayOne = new string[number];
  30. string[] arrayTwo = new string[number];
  31.  
  32. for (int i = 0; i < number; i++)
  33. {
  34. string[] current = Console.ReadLine().Split();
  35. if (i % 2 == 0)
  36. {
  37. arrayOne[i] = current[0];
  38. arrayTwo[i] = current[1];
  39. }
  40. else
  41. {
  42. arrayOne[i] = current[1];
  43. arrayTwo[i] = current[0];
  44. }
  45. }
  46. Console.WriteLine(string.Join(" ", arrayOne));
  47. Console.WriteLine(string.Join(" ", arrayTwo));
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment