Advertisement
onqkoie

Untitled

Apr 30th, 2020
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _5._Snake_Moves
  6. {
  7. class StartUp
  8. {
  9. static void Main(string[] args)
  10. {
  11. var dimensions = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  12.  
  13. int rows = dimensions[0];
  14. int cols = dimensions[1];
  15. var matrix = new char[rows, cols];
  16.  
  17. string snake = Console.ReadLine();
  18. int index = 0;
  19. for (int row = 0; row < rows; row++)
  20. {
  21. var curRow = new List<char>();
  22. while(curRow.Count <= rows)
  23. {
  24. curRow.Add(snake[index]);
  25. index++;
  26. if (index > cols)
  27. {
  28. index = 0;
  29. }
  30. }
  31. if (row % 2 == 1)
  32. {
  33. curRow.Reverse();
  34. }
  35. for (int col = 0; col < cols; col++)
  36. {
  37. matrix[row, col] = curRow[col];
  38. }
  39. }
  40.  
  41. for (int row = 0; row < rows; row++)
  42. {
  43. for (int col = 0; col < cols; col++)
  44. {
  45. Console.Write(matrix[row, col]);
  46. }
  47. Console.WriteLine();
  48. }
  49.  
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement